Loop thru the dictionary with tuples

Chris Angelico rosuav at gmail.com
Sun May 25 09:58:55 EDT 2014


On Sun, May 25, 2014 at 11:22 PM, Roy Smith <roy at 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



More information about the Python-list mailing list