Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does enumerate create a copy of its argument?

If I use enumerate while iterating through a very large list of graph clusters, I want to make sure I'm not unnecessarily creating any copies of this list in memory.

I've been trying to confirm that it will not create any copies, but would like to know for sure.

for i, cluster in enumerate(c):
    # code that does stuff with i and cluster
like image 994
punkrockpolly Avatar asked Apr 11 '14 14:04

punkrockpolly


1 Answers

No, it doesn't. It lazily iterates the iterable you pass in while the loop executes.

like image 68
Sven Marnach Avatar answered Oct 23 '22 07:10

Sven Marnach