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


Groups > comp.lang.python > #15313

Re: Dictionary sorting

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.011
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; '"if': 0.04; 'python': 0.08; 'am,': 0.12; 'case.': 0.15; '(k,': 0.16; '[(v,': 0.16; 'correspond.': 0.16; 'dictionary,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'intervening': 0.16; 'key)': 0.16; 'wrote:': 0.18; 'holds': 0.21; 'header:In-Reply- To:1': 0.23; 'expect': 0.25; 'lists': 0.28; 'message- id:@mail.gmail.com': 0.29; 'differently': 0.30; 'list1': 0.30; 'url:library': 0.30; 'nov': 0.31; 'does': 0.32; "can't": 0.32; 'list': 0.32; 'quite': 0.32; 'to:addr:python-list': 0.32; 'there': 0.33; 'things': 0.35; 'received:209.85.216.46': 0.35; 'received :mail-qw0-f46.google.com': 0.35; 'url:python': 0.35; 'fri,': 0.36; 'another': 0.36; 'but': 0.37; 'using': 0.37; 'allows': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'called': 0.38; 'url:org': 0.38; 'url:docs': 0.38; '(with': 0.39; 'subject:: ': 0.39; 'skip:z 10': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; 'tim': 0.40; '2011': 0.62; 'guarantee': 0.66
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=GRB57gIy8sSdN/nH3yfN1debPE/nICTGtEm7NrFVTg4=; b=Zh+GDL0EHRZswMzqoamraEszEuUFh0Tgvv6/2DtJbFmOVMNtDYNdBZwfqqcxnh/OJP 6ZBIYgN8Ftgy+uOFkXeB2OUCBIAH36weCbENCxLfjeIMtkdOfRSZoPU4cZ4bT51o2usc Ws0mIe+B1MwdQ9Nw8Rsk6XHhyQX/BqHwbs9ww=
MIME-Version 1.0
In-Reply-To <4EB31D52.3080707@tim.thechases.com>
References <16245908.783.1320346014867.JavaMail.geo-discussion-forums@yqhd1> <j8v1h5$4mc$1@dough.gmane.org> <4EB31D52.3080707@tim.thechases.com>
Date Fri, 4 Nov 2011 10:59:43 +1100
Subject Re: Dictionary sorting
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2420.1320364788.27778.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1320364788 news.xs4all.nl 6903 [2001:888:2000:d::a6]:34907
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15313

Show key headers only | View raw


On Fri, Nov 4, 2011 at 10:01 AM, Tim Chase
<python.list@tim.thechases.com> wrote:
>  list1 = list(d.iterkeys())
>  list2 = list(d.iterkeys())
>  assert list1 == list2
>

There is such a guarantee in Python 2. From
http://docs.python.org/library/stdtypes.html:
"If items(), keys(), values(), iteritems(), iterkeys(), and
itervalues() are called with no intervening modifications to the
dictionary, the lists will directly correspond. This allows the
creation of (value, key) pairs using zip(): pairs = zip(d.values(),
d.keys()). The same relationship holds for the iterkeys() and
itervalues() methods: pairs = zip(d.itervalues(), d.iterkeys())
provides the same value for pairs. Another way to create the same list
is pairs = [(v, k) for (k, v) in d.iteritems()]."

Python 3 does things quite differently (with views), and I can't find
a corresponding promise, but I expect that this would still be the
case.

ChrisA

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


Thread

Dictionary sorting Scott Ware <scottdware@gmail.com> - 2011-11-03 11:46 -0700
  Re: Dictionary sorting John Gordon <gordon@panix.com> - 2011-11-03 18:57 +0000
    Re: Dictionary sorting Scott Ware <scottdware@gmail.com> - 2011-11-03 12:00 -0700
      Re: Dictionary sorting Chris Kaynor <ckaynor@zindagigames.com> - 2011-11-03 12:13 -0700
  Re: Dictionary sorting insomnia@gmail.com - 2011-11-03 13:01 -0700
  Re: Dictionary sorting Terry Reedy <tjreedy@udel.edu> - 2011-11-03 17:36 -0400
  Re: Dictionary sorting Tim Chase <python.list@tim.thechases.com> - 2011-11-03 18:01 -0500
    Re: Dictionary sorting Ben Finney <ben+python@benfinney.id.au> - 2011-11-04 11:06 +1100
      Re: Dictionary sorting Hrvoje Niksic <hniksic@xemacs.org> - 2011-11-04 11:20 +0100
        Re: Dictionary sorting Ben Finney <ben+python@benfinney.id.au> - 2011-11-04 23:19 +1100
  Re: Dictionary sorting Chris Angelico <rosuav@gmail.com> - 2011-11-04 10:59 +1100

csiph-web