DEV Community

Discussion on: Common Programming Questions: The Fibonacci Sequence

Collapse
 
robinloche profile image
robin-loche

In python, you could also access the last items of the list using the minus indexes (list[-1] access the last element of the list), especially since you have already 2 items in your list. The inside of the loop would become only:
fibonacci_list.append(fibonacci_list[-2] + fibonacci_list[-1])

Collapse
 
carrotfarmer profile image
Dhruva Srinivas

Oh yes, that didn't occur to me, Thank you so much for sharing :)