3 ms·
Pythons generators are similar to that idea, although it's not their official use. Using 'yield' instead of 'return' in python lets you return to that function
by kedean 14y ago
Pythons generators are similar to that idea, although it's not their official use. Using 'yield' instead of 'return' in python lets you return to that function at the same point of execution later on (using .next()), at which time you could have changed member variables of the class wrapping that function, effectively modifying the environment of the function, yet the local variables are exactly as they were and so execution still proceeds as it should.
Normally this is used for producing very large lists in an on-demand manner, rather than precomputing, but it can be abused for some very unique things.