Skip to content
Advertisement

Is enumerate in python lazy?

I’d like to know what happens when I pass the result of a generator function to python’s enumerate(). Example:

JavaScript

Is the enumeration iterated lazily, or does it slurp everything into the <enumerate object> first? I’m 99.999% sure it’s lazy, so can I treat it exactly the same as the generator function, or do I need to watch out for anything?

Advertisement

Answer

It’s lazy. It’s fairly easy to prove that’s the case:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement