Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72004
| Date | 2014-05-25 08:07 -0500 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: Loop thru the dictionary with tuples |
| References | <mailman.10291.1401022510.18130.python-list@python.org> <7x61kuc8uc.fsf@ruckus.brouhaha.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.10293.1401023275.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
On 2014-05-25 05:59, Paul Rubin wrote:
> 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(): ...
You can even use
for ((k1,k2,k3), value) in mydict.iteritems():
...
if you need to unpack the key at the same time.
-tkc
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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