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


Groups > comp.lang.python > #63945

Re:dictionary with tuples

From Dave Angel <davea@davea.name>
Subject Re:dictionary with tuples
Date 2014-01-14 16:32 -0500
Organization news.gmane.org
References <CA+FnnTyBnns_hkj4ur1y4ySGD_HqtGpc8GNiFhLio31x6eqbKA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5481.1389735046.18130.python-list@python.org> (permalink)

Show all headers | 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