Does enumerate create a copy of its argument?

守給你的承諾、 提交于 2019-12-12 11:15:10

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/23015133/does-enumerate-create-a-copy-of-its-argument

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!