Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63953
| From | emile <emile@fenx.com> |
|---|---|
| Subject | Re: dictionary with tuples |
| Date | 2014-01-14 14:14 -0800 |
| References | <mailman.5476.1389733811.18130.python-list@python.org> <52d5aa4c$0$2196$426a74cc@news.free.fr> <GriBu.177658$Qi4.154313@fx11.iad> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5487.1389737708.18130.python-list@python.org> (permalink) |
On 01/14/2014 02:00 PM, Tobiah wrote:
> On 01/14/2014 01:21 PM, YBM wrote:
>> Le 14/01/2014 22:10, Igor Korot a écrit :
>>> 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?
>>
>> for ... in dict:
>>
>> is a way to iterate through dictionnary items,
>>
>> what you want to do can be done so:
>>
>> for (key1,key2),(value1,value2) in dict.items():
>>
>>
>>
>
> But it's (key1, value1), (key2, value2)
No it isn't. :)
Emile
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
dictionary with tuples Igor Korot <ikorot01@gmail.com> - 2014-01-14 13:10 -0800
Re: dictionary with tuples YBM <ybmess@nooos.fr.invalid> - 2014-01-14 22:21 +0100
Re: dictionary with tuples Tobiah <toby@tobiah.org> - 2014-01-14 14:00 -0800
Re: dictionary with tuples emile <emile@fenx.com> - 2014-01-14 14:14 -0800
Re: dictionary with tuples YBM <ybmess@nooos.fr.invalid> - 2014-01-15 03:24 +0100
csiph-web