Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!takemy.news.telefonica.de!telefonica.de!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'win32': 0.03; 'builtin': 0.09; 'iterate': 0.09; 'python': 0.11; "('c',": 0.16; '-tkc': 0.16; '2)]': 0.16; 'dict': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'igor': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'bit': 0.19; '>>>': 0.22; 'header:In-Reply-To:1': 0.27; 'skip:( 20': 0.30; 'another': 0.32; "i'd": 0.34; 'subject:with': 0.35; 'doing': 0.36; 'charset :us-ascii': 0.36; 'hi,': 0.36; 'should': 0.36; 'to:addr:python- list': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'name:': 0.61; 'choose': 0.64; 'more': 0.64; 'received:50.22': 0.84; 'shadow': 0.84; '2013,': 0.91 Date: Tue, 14 Jan 2014 15:18:57 -0600 From: Tim Chase To: python-list@python.org Subject: Re: dictionary with tuples In-Reply-To: References: X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389734284 news.xs4all.nl 2912 [2001:888:2000:d::a6]:44074 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63940 On 2014-01-14 13:10, Igor Korot wrote: > Hi, ALL, > C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python > Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more > information. > >>> dict = {} > >>> dict[(1,2)] = ('a','b') > >>> dict[(3,4)] = ('c','d') > >>> for (key1,key2),(value1,value2) in dict: > > What am I doing wrong? You should iterate over either dict.items() or dict.iteritems() Also, it's bad practice to shadow the builtin "dict()", so I'd choose another name: d = {} d[(1, 2)] = ('a', 'b') d[(3, 4)] = ('c', 'd') for (k1, k2), (v1, v2) in d.iteritems(): do_something(k1, k2, v1, v2) -tkc