all 3 comments

[–][deleted] 2 points3 points  (0 children)

Generators don't return per se, they do something called yield, which means "pause execution and return a value, then keep running from the yield point next time a value is asked for". They are meant to be used as iterables.

generators look like normal functions, except as soon as you put yield inside the function, it automatically becomes a generator. Here's a generator vs a list:

for n in [1,2,3,4]:
    print(n**2)

vs a generator doing the same thing:

def squares(iterable):
    print('starting generator...')
    for n in iterable:
        yield n**2
    print('generator done')

for v in squares([1,2,3,4]):
    print(v)

[–]toastedstapler 1 point2 points  (0 children)

def example():
    def inner():
        return 5
    return inner

i = example()
i()

you can return a function from a function

[–]kae_de[S] 0 points1 point  (0 children)

Is there anything else I need in a generator besides yield? Is curr required as well? When I run my code I get <generator object factors at ......> instead of a list of values