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

2018-09-07 Thread Oscar Benjamin
On Fri, 7 Sep 2018 at 16:25, Schachner, Joseph wrote: >... > Now, on to the second part: the problem you showed - that you can only loop > through aList:print(i,j) once - is BECAUSE you hung onto it from one loop to > another. Once the iterator is exhausted, it's exhausted. > > Think of

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

2018-09-07 Thread Schachner, Joseph
The question "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?" Reflects that you are thinking in a C++ kind of way I think.

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

2018-09-06 Thread Steven D'Aprano
On Thu, 06 Sep 2018 11:50:17 -0700, Viet Nguyen via Python-list wrote: > If I do this "aList = enumerate(numList)", isn't it > stored permanently in aList now? Yes, but the question is "what is *it* that is stored? The answer is, it isn't a list, despite the name you choose. It is an enumerate

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

2018-09-06 Thread Viet Nguyen via Python-list
On Thursday, September 6, 2018 at 12:12:20 PM UTC-7, David Raymond wrote: > The actual "enumerate" object is really just holding a current index and a > reference to the original list. So if you alter the original list while > you're iterating through it you'll see the changes. If you want a

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

2018-09-06 Thread Chris Angelico
On Fri, Sep 7, 2018 at 4:50 AM, Viet Nguyen via Python-list 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

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

2018-09-06 Thread David Raymond
The actual "enumerate" object is really just holding a current index and a reference to the original list. So if you alter the original list while you're iterating through it you'll see the changes. If you want a full copy then you can just wrap it with list() Python 3.7.0 (v3.7.0:1bf9cc5093,

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

2018-09-06 Thread Viet Nguyen via Python-list
On Thursday, September 6, 2018 at 10:34:19 AM UTC-7, Chris Angelico wrote: > On Fri, Sep 7, 2018 at 3:26 AM, Viet Nguyen via Python-list > wrote: > numList > > [2, 7, 22, 30, 1, 8] > > > aList = enumerate(numList) > > > for i,j in aList:print(i,j) > > > > 0 2 > > 1 7 > > 2 22 > > 3

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

2018-09-06 Thread Chris Angelico
On Fri, Sep 7, 2018 at 3:26 AM, Viet Nguyen via Python-list wrote: numList > [2, 7, 22, 30, 1, 8] > aList = enumerate(numList) > for i,j in aList:print(i,j) > > 0 2 > 1 7 > 2 22 > 3 30 > 4 1 > 5 8 > for i,j in aList:print(i,j) > Because it's not an enumerated list, it's