I am trying to wrap my head around generator and yield in python. I understand that a function that has an yield returns a generator object. However if I try to convert that generator object to a list it hangs my machine. I am trying to figure out why that is. And what is a more elegant way if any to convert a generator object to a list.
def fib():
a, b = 0, 1
while True:
yield a
a, b = b, a + b
a = fib()
print(type(a))
b = fib()
print(type(b))
print(list(b))
Output
<class 'generator'>
<class 'generator'>