Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.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; 'win32': 0.03; 'method.': 0.07; 'builtin': 0.09; 'iterate': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'wrote': 0.14; 'dict': 0.16; 'igor': 0.16; 'iterable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'typeerror:': 0.16; 'all,': 0.19; 'bit': 0.19; 'trying': 0.19; "hasn't": 0.19; 'things.': 0.19; 'print': 0.22; "shouldn't": 0.24; 'header:X -Complaints-To:1': 0.27; 'forgot': 0.30; 'skip:( 20': 0.30; '"",': 0.31; '3.x': 0.31; '>>>>': 0.31; 'file': 0.32; '(most': 0.33; 'problem': 0.35; 'subject:with': 0.35; 'but': 0.35; 'really': 0.36; 'doing': 0.36; 'next': 0.36; 'hi,': 0.36; 'should': 0.36; 'two': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; "you're": 0.61; 'you.': 0.62; 'name': 0.63; 'real': 0.63; 'pick': 0.64; 'more': 0.64; 'different': 0.65; 'dict.': 0.84; 'shadow': 0.84; 'subject::': 0.85; '2013,': 0.91; 'items,': 0.91; 'url:tk': 0.95 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re:dictionary with tuples Date: Tue, 14 Jan 2014 16:32:39 -0500 (EST) Organization: news.gmane.org References: X-Gmane-NNTP-Posting-Host: dpc6744192080.direcpc.com X-Newsreader: PiaoHong NewsGroups Reader 1.36 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389735046 news.xs4all.nl 2854 [2001:888:2000:d::a6]:32825 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63945 Igor Korot Wrote in message: > 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: > ... print key1, " ", key2 > ... print value1, " ", value2 > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: 'int' object is not iterable >>>> > > What am I doing wrong? > > Thank you. > Two things. You really shouldn't shadow a builtin with your own locals, though it hasn't hurt you this time. Next time pick a different name than dict. Your real problem is that you're trying to iterate over items, but forgot to use that method. The for loop line should end in dict.items () : You may be confused, since it's different in python 3.x -- DaveA ----Android NewsGroup Reader---- http://www.piaohong.tk/newsgroup