The Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……..
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
Fn = Fn-1 + Fn-2 with seed values F0 = 0 and F1 = 1.
Find the series of fibonacci numbers using lambda function.
Code #1 : By using lambda and reduce method
[0, 1, 1, 2, 3]
The list taking first two parameters is 0 and 1, and add like x[-1] i.e 0 and x[-2] i.e 1 and append to variable x. There is a type conversion to list and due to
reduce() method, the same function calls and due to range function this time parameter changes, then add this to previous result and again store it to list.
Code #2 : By using lambda and map function
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
We are taking the list fib_list which already has 0 and 1. Then in the next iteration, this will be used as input and result of their sum will append to the list.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Find the Number Occurring Odd Number of Times using Lambda expression and reduce function
- Ways to sort list of dictionaries by values in Python - Using lambda function
- Python Program to Sort the list according to the column using lambda
- Sum of Fibonacci numbers at even indexes upto N terms
- Count of numbers whose difference with Fibonacci count upto them is atleast K
- Lambda and filter in Python Examples
- Map function and Lambda expression in Python to replace characters
- Intersection of two arrays in Python ( Lambda expression and filter function )
- Overuse of lambda expressions in Python
- Difference between List comprehension and Lambda in Python
- Python | sympy.Lambda() method
- Python lambda
- Python Lambda with underscore as an argument
- Nested Lambda Function in Python
- Python lambda (Anonymous Functions) | filter, map, reduce
- Lambda expression in Python to rearrange positive and negative numbers
- Applying Lambda functions to Pandas Dataframe
- Check if a M-th fibonacci number divides N-th fibonacci number
- Check if sum of Fibonacci elements in an Array is a Fibonacci number or not
- Find n terms of Fibonacci type series with given first two terms
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.