Skip to content

Instantly share code, notes, and snippets.

@cristinelpopescu
Created April 13, 2021 11:12
Show Gist options
  • Save cristinelpopescu/b0c98bdd6f55e69c5a7ef873b703e55c to your computer and use it in GitHub Desktop.
Save cristinelpopescu/b0c98bdd6f55e69c5a7ef873b703e55c to your computer and use it in GitHub Desktop.
# fibonacci - generator
def fib(number):
a = 0
b = 1
for i in range(number):
yield a
temp = a
a = b
b = temp + b
for x in fib(20):
print(x)
# fibonacci - list
def fib2(number):
a = 0
b = 1
result =[]
for i in range(number):
result.append(a)
temp = a
a = b
b = temp + b
return result
print(fib2(20))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment