I'm a newbie and I'm trying to get my head around the enumerate function, and the behaviour of the enumerate object it generates.
Referencing the enumerate object seems to deplete it of its entries. Trying to interact with it in the same way twice in a row provides different results.
I've been thinking of it like a list, but this clearly isn't the way this kind of object behaves. Could somebody explain this spooky behaviour to me or direct me towards some resources that will?
MyList = ['one','two','three']
EnumList = enumerate(MyList,start=1)
print("Pass 1:")
print(EnumList)
for i in EnumList:
print(i)
print("\nPass 2:")
print(EnumList)
for i in EnumList:
print(i)
print("\nEnd")
Output:
Pass 1:
<enumerate object at 0x000001D79D0B4DB8>
(1, 'one')
(2, 'two')
(3, 'three')
Pass 2:
<enumerate object at 0x000001D79D0B4DB8>
End