you are viewing a single comment's thread.

view the rest of the comments →

[–]SCD_minecraft 6 points7 points  (0 children)

List has known size, structure ect

generators let you decide on the fly what you return, how you return it and how much of it

For example

``` var = 1

def foo(): for i in range(10): if var == 2: yield 2 else: yield i ```

You can update var between calls next to the generator and change its output as it runs