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: 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 Subject: Re: Loop thru the dictionary with tuples Date: Sun, 25 May 2014 09:58:04 -0400 References: 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: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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