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


Groups > comp.lang.python > #63945

Re:dictionary with tuples

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 <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; '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 <davea@davea.name>
Subject Re:dictionary with tuples
Date Tue, 14 Jan 2014 16:32:39 -0500 (EST)
Organization news.gmane.org
References <CA+FnnTyBnns_hkj4ur1y4ySGD_HqtGpc8GNiFhLio31x6eqbKA@mail.gmail.com>
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 <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.5481.1389735046.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


 Igor Korot <ikorot01@gmail.com> 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 "<stdin>", line 1, in <module>
> 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

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


Thread

Re:dictionary with tuples Dave Angel <davea@davea.name> - 2014-01-14 16:32 -0500

csiph-web