Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #72003

Re: Loop thru the dictionary with tuples

From Paul Rubin <no.email@nospam.invalid>
Newsgroups comp.lang.python
Subject Re: Loop thru the dictionary with tuples
Date 2014-05-25 05:59 -0700
Organization Nightsong/Fort GNOX
Message-ID <7x61kuc8uc.fsf@ruckus.brouhaha.com> (permalink)
References <mailman.10291.1401022510.18130.python-list@python.org>

Show all headers | View raw


Igor Korot <ikorot01@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(): ...
otherwise you loop through just the keys, whicn in your dictionary 
happens to be 3-tuples.  So you try to unpack a 3-tuple to a 2-tuple
and get a too-many-values error.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Loop thru the dictionary with tuples Igor Korot <ikorot01@gmail.com> - 2014-05-25 05:55 -0700
  Re: Loop thru the dictionary with tuples Paul Rubin <no.email@nospam.invalid> - 2014-05-25 05:59 -0700
    Re: Loop thru the dictionary with tuples Tim Chase <python.list@tim.thechases.com> - 2014-05-25 08:07 -0500
  Re: Loop thru the dictionary with tuples Roy Smith <roy@panix.com> - 2014-05-25 09:22 -0400
    Re: Loop thru the dictionary with tuples Chris Angelico <rosuav@gmail.com> - 2014-05-25 23:58 +1000

csiph-web