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


Groups > comp.lang.python > #63940 > unrolled thread

Re: dictionary with tuples

Started byTim Chase <python.list@tim.thechases.com>
First post2014-01-14 15:18 -0600
Last post2014-01-14 15:18 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: dictionary with tuples Tim Chase <python.list@tim.thechases.com> - 2014-01-14 15:18 -0600

#63940 — Re: dictionary with tuples

FromTim Chase <python.list@tim.thechases.com>
Date2014-01-14 15:18 -0600
SubjectRe: dictionary with tuples
Message-ID<mailman.5478.1389734284.18130.python-list@python.org>
On 2014-01-14 13: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:
> 
> What am I doing wrong?

You should iterate over either dict.items() or dict.iteritems()

Also, it's bad practice to shadow the builtin "dict()", so I'd choose
another name:

  d = {}
  d[(1, 2)] = ('a', 'b')
  d[(3, 4)] = ('c', 'd')
  for (k1, k2), (v1, v2) in d.iteritems():
    do_something(k1, k2, v1, v2)

-tkc

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web