Sep-16-2018, 02:47 PM
The enumate function expressed as generator looks like this:
def enum_gen(iterable, start=0, step=1) for element in iterable: yield (start, element) # <- Here the generator is paused till the next iteration start += step # increment the internal counter by step gen = enum_gen([1,2,3,4]) # <- This creates the generator, no code execution next(gen) # this is what the for-loop does implicit # until a StopIteration has been raised. # the Exception comes from the generator, when it has been finished with the for-loop
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!