dictionary with tuples
Dave Angel
davea at davea.name
Tue Jan 14 16:32:39 EST 2014
Igor Korot <ikorot01 at 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
More information about the Python-list
mailing list