I was just curious about this and thought this should logically work in python. I tried the following code in the python console:
mylist = [('a','b'),('c','d')]
for i,x,y in enumerate(mylist):
print i,x,y
ValueError: need more than 2 values to unpack
But if I try to not enumerate and just do the following:
mylist = [('a','b'),('c','d')]
for i,x in mylist:
print i,x
it works fine. I was just wondering why the first method doesn't work as that shouldn't really hinder python unpacking values from tuples should it? Unless I have overlooked something embarrassingly simple. I'd really like to know the reason for this peculiar behavior.
How to generate enumerated tuples from a dictionary with a list comprehension in Python?
says that the value of enumerate() function is a two element tuple. But in my case the second element of the tuple returned by enumerate would itself be a tuple so why can it not be unpacked?