Loop thru the dictionary with tuples
Tim Chase
python.list at tim.thechases.com
Sun May 25 09:07:14 EDT 2014
On 2014-05-25 05:59, Paul Rubin wrote:
> Igor Korot <ikorot01 at gmail.com> writes:
> > for (key,value) in my_dict:
> > #Do some stuff
> >
> > but I'm getting an error "Too many values to unpack".
>
> Use
> for (key,value) in mydict.iteritems(): ...
You can even use
for ((k1,k2,k3), value) in mydict.iteritems():
...
if you need to unpack the key at the same time.
-tkc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20140525/c19d22e3/attachment.sig>
More information about the Python-list
mailing list