Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72003
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Paul Rubin <no.email@nospam.invalid> |
| Newsgroups | comp.lang.python |
| Subject | Re: Loop thru the dictionary with tuples |
| Date | Sun, 25 May 2014 05:59:39 -0700 |
| Organization | Nightsong/Fort GNOX |
| Lines | 11 |
| Message-ID | <7x61kuc8uc.fsf@ruckus.brouhaha.com> (permalink) |
| References | <mailman.10291.1401022510.18130.python-list@python.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | mx05.eternal-september.org; posting-host="8ff39c3b56f8fea9a226ae9d8294e48e"; logging-data="5935"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193R6OI8qFNNIKQ5gtdib2p" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:5yXayydsog0GwS4/sSidj2mtBow= sha1:Wc1ZiD8+ObbNA/DYpEp62wpL85w= |
| Xref | csiph.com comp.lang.python:72003 |
Show key headers only | 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 | 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