2 ms·
Don't forget you can chain multiple generators together too. This can have huge memory and compute time benefits with lazy evaluation depending how you structur
by wfitz 3y ago
Don't forget you can chain multiple generators together too. This can have huge memory and compute time benefits with lazy evaluation depending how you structure your code. A very crude example below...
# Really big generator that would probably crash as a list
divmods = (divmod(x,5) for x in range(100000000000000000000000000000000))
# Create a generator from a generator
remains = (remainder for n, remainder in divmods)
# Runs instantly
next(remains)