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


Groups > comp.lang.python > #72008

Re: Loop thru the dictionary with tuples

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'igor': 0.16; 'iterating': 0.16; 'keys.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'trying': 0.19; 'header:User- Agent:1': 0.23; 'error': 0.23; 'received:comcast.net': 0.24; 'this:': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "i'm": 0.30; 'gives': 0.31; 'getting': 0.31; 'stuff': 0.32; 'subject:the': 0.34; 'subject:with': 0.35; 'but': 0.35; 'doing': 0.36; 'hi,': 0.36; 'thank': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'you.': 0.62; '"too': 0.84; 'want:': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: Loop thru the dictionary with tuples
Date Sun, 25 May 2014 09:58:04 -0400
References <CA+FnnTwpQKTyvROYq32YsDfwDooDXRbRg-SYGGhFs1T1D9o_Ow@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host c-50-133-228-126.hsd1.ma.comcast.net
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
In-Reply-To <CA+FnnTwpQKTyvROYq32YsDfwDooDXRbRg-SYGGhFs1T1D9o_Ow@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10296.1401026296.18130.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1401026296 news.xs4all.nl 2938 [2001:888:2000:d::a6]:60573
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72008

Show key headers only | View raw


On 5/25/14 8:55 AM, Igor Korot wrote:
> Hi, ALL,
> I have a following data structure:
>
> my_dict[(var1,var2,var3)] = None
> my_dict[(var4,var5,var6)] = 'abc'
>
> What I'm trying to do is this:
>
> for (key,value) in my_dict:
>      #Do some stuff
>
> but I'm getting an error "Too many values to unpack".
>
> What am I doing wrong?
>
> Thank you.
>

You want:

     for key, value in my_dict.items():  # or .iteritems()

Iterating over a dictionary gives you its keys.  items() will give you 
key,value pairs.

-- 
Ned Batchelder, http://nedbatchelder.com

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


Thread

Re: Loop thru the dictionary with tuples Ned Batchelder <ned@nedbatchelder.com> - 2014-05-25 09:58 -0400

csiph-web