Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.etla.org!news.stack.nl!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'win32': 0.03; 'classes.': 0.09; 'iterate': 0.09; 'keys,': 0.09; 'python': 0.11; 'dict': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'igor': 0.16; 'iterable': 0.16; 'iterating': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'bit': 0.19; 'print': 0.22; 'header:User-Agent:1': 0.23; 'instead.': 0.24; 'header:In-Reply-To:1': 0.27; 'skip:( 20': 0.30; '"",': 0.31; '>>>>': 0.31; 'keys': 0.31; 'values.': 0.31; 'yields': 0.31; 'file': 0.32; '(most': 0.33; 'subject:with': 0.35; 'doing': 0.36; 'hi,': 0.36; 'thank': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'you.': 0.62; 'such': 0.63; 'more': 0.64; 'header:Reply-To:1': 0.67; 'reply- to:no real name:2**0': 0.71; 'reply-to:addr:python.org': 0.84; '2013,': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=CfYxutbl c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=5FYZ9MsUIQAA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=rwO_9jovjrcA:10 a=4a5my3lO3jp01RhyEqkA:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett:2500 Date: Tue, 14 Jan 2014 21:21:56 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: dictionary with tuples References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389734518 news.xs4all.nl 2942 [2001:888:2000:d::a6]:48881 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63942 On 2014-01-14 21: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: > ... 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. > When you iterate over a dict it yields the only the keys, not the keys and values. Try iterating over dict.items() instead. By the way, try not to use names such as 'dict' that are the names of built-in classes.