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


Groups > comp.lang.python > #72042

Re: Loop thru the dictionary with tuples

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!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; 'wrote': 0.14; 'dict': 0.16; '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; 'error': 0.23; 'large,': 0.24; 'this:': 0.26; 'values': 0.27; 'header:X-Complaints-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; 'batchelder': 0.84; 'want:': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re: Loop thru the dictionary with tuples
Date Sun, 25 May 2014 22:09:28 -0400 (EDT)
Organization news.gmane.org
References <CA+FnnTwpQKTyvROYq32YsDfwDooDXRbRg-SYGGhFs1T1D9o_Ow@mail.gmail.com> <llsstb$1sa$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host dpc6744193092.direcpc.com
X-Newsreader PiaoHong.NewsGroup.Client.VIP:1.52
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.10324.1401070147.18130.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1401070147 news.xs4all.nl 2860 [2001:888:2000:d::a6]:39021
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72042

Show key headers only | View raw


Ned Batchelder <ned@nedbatchelder.com> Wrote in message:
> 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.


Or, if the dict is large,  you might want

for key in my_dict:
    value = my_dict [key]
    ...


-- 
DaveA

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


Thread

Re: Loop thru the dictionary with tuples Dave Angel <davea@davea.name> - 2014-05-25 22:09 -0400

csiph-web