[Tutor] How to get the keys of a dict inside a dict. ValueError: too many values to unpack

Steve Willoughby steve at alchemy.com
Sun Aug 7 18:45:54 CEST 2011


On 07-Aug-11 09:17, Steve Willoughby wrote:

> First of all, that's not a dict. It's just a tuple of strings.
> so, when you say:
>
>> #loop through and get the keys of each
>> for k,v in x:
>
> You'll get one iteration, where k=the first string and v=the second.
> However, you ignore k and v in all the code that follows, so I'm really
> confused what you're trying to do here.

I just noticed I glossed over a key point, for that to work you'd need x 
to be a sequence of such tuples.  As it stands there, you'll get an 
error because each element of x is a single string, so it can't pull two 
values out of each of them.

-- 
Steve Willoughby / steve at alchemy.com
"A ship in harbor is safe, but that is not what ships are built for."
PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C


More information about the Tutor mailing list