Generates a Fibonacci sequence of a given length.
Contributed by @itsbrunodev
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
arr = []
for num in fibonacci(10):
arr.append(num)
# [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]