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


Groups > comp.lang.python > #72009

Re: Loop thru the dictionary with tuples

References <mailman.10291.1401022510.18130.python-list@python.org> <roy-F52825.09220325052014@news.panix.com>
Date 2014-05-25 23:58 +1000
Subject Re: Loop thru the dictionary with tuples
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.10297.1401026343.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, May 25, 2014 at 11:22 PM, Roy Smith <roy@panix.com> wrote:
> Hint: in this case,
> it will happen on the assignment line, so, your next step is to print
> everything out and see what's going on:
>
> for thing in my_dict:
>     print thing
>     (key, value) = thing

Aside: I know that you (Roy) are still using Python 2, but the OP
could be on either branch. As a matter of safety, I'd put parens
around the print:

for thing in my_dict:
    print(thing)
    (key, value) = thing

That way, it works on either.

ChrisA

Back to comp.lang.python | Previous | NextPrevious 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