Why emumerated list is empty on 2nd round of print?

Chris Angelico rosuav at gmail.com
Thu Sep 6 15:21:41 EDT 2018


On Fri, Sep 7, 2018 at 4:50 AM, Viet Nguyen via Python-list
<python-list at python.org> wrote:
>> Because it's not an enumerated list, it's an enumerated iterator.
>> Generally, you'll just use that directly in the loop:
>>
>> for i, value in enumerate(numbers):
>>
>> There's generally no need to hang onto it from one loop to another.
>>
>> ChrisA
>
> Thanks ChrisA. If I do this "aList = enumerate(numList)", isn't it stored permanently in aList now?  I see your point to use it directly, but just in case I do need to hang onto it from one loop to another, then how is that done?   Anyway I think I'm ok and I got what I need for now.
>

The enumerator is. It doesn't become something different when you
assign it to something. Assume you don't need to hang onto it, until
such time as that changes. :)

ChrisA



More information about the Python-list mailing list