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


Groups > comp.lang.python > #25851

Re: dict: keys() and values() order guaranteed to be same?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin.stu.neva.ru!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <phihag@phihag.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'subject:keys': 0.09; 'subject:same': 0.09; 'cc:addr:python-list': 0.10; 'correspond.': 0.16; 'dictionary,': 0.16; 'filename:fname piece:signature': 0.16; 'intervening': 0.16; 'order?': 0.16; 'subject:values': 0.16; 'wrote:': 0.17; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; '[1]': 0.27; 'though.': 0.29; 'yes.': 0.29; 'lists': 0.31; 'url:python': 0.32; 'cases,': 0.33; 'received:192.168.2': 0.34; 'pm,': 0.35; 'subject:?': 0.35; 'url:org': 0.36; 'url:library': 0.36; 'should': 0.36; 'subject:: ': 0.38; 'url:docs': 0.38; 'received:192': 0.39; 'called': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'most': 0.61; 'needing': 0.62; 'url:items': 0.84
Date Mon, 23 Jul 2012 13:40:42 +0200
From Philipp Hagemeister <phihag@phihag.de>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:10.0.5) Gecko/20120624 Icedove/10.0.5
MIME-Version 1.0
To Henrik Faber <hfaber@invalid.net>
Subject Re: dict: keys() and values() order guaranteed to be same?
References <jujc6j$rk5$1@speranza.aioe.org>
In-Reply-To <jujc6j$rk5$1@speranza.aioe.org>
X-Enigmail-Version 1.4
OpenPGP id=FAFB085C
Content-Type multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enigC72216755753D59E47BE29CD"
Cc python-list@python.org
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.2460.1343043655.4697.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1343043655 news.xs4all.nl 6875 [2001:888:2000:d::a6]:34111
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25851

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 07/23/2012 01:23 PM, Henrik Faber wrote:
> With an arbitrary dictionaty d, are d.keys() and d.values()
> guaraneed to be in the same order?

Yes. From the documentation[1]:

If items(), keys(), values(), iteritems(), iterkeys(), and itervalues()
are called with no intervening modifications to the dictionary, the
lists will directly correspond.

In most cases, you should simply use items() though. Can you elaborate
on the use case for needing both keys() and values(), where items() is
not applicable?

- Philipp

[1] http://docs.python.org/library/stdtypes.html#dict.items

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


Thread

dict: keys() and values() order guaranteed to be same? Henrik Faber <hfaber@invalid.net> - 2012-07-23 13:23 +0200
  Re: dict: keys() and values() order guaranteed to be same? Philipp Hagemeister <phihag@phihag.de> - 2012-07-23 13:40 +0200
    Re: dict: keys() and values() order guaranteed to be same? Henrik Faber <hfaber@invalid.net> - 2012-07-23 14:19 +0200
  Re: dict: keys() and values() order guaranteed to be same? Stefan Behnel <stefan_ml@behnel.de> - 2012-07-23 13:43 +0200
  Re: dict: keys() and values() order guaranteed to be same? Stefan Behnel <stefan_ml@behnel.de> - 2012-07-23 13:58 +0200
    Re: dict: keys() and values() order guaranteed to be same? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-23 15:20 +0000
      Re: dict: keys() and values() order guaranteed to be same? Chris Angelico <rosuav@gmail.com> - 2012-07-24 02:18 +1000
      Re: dict: keys() and values() order guaranteed to be same? Ethan Furman <ethan@stoneleaf.us> - 2012-07-26 14:06 -0700
      Re: dict: keys() and values() order guaranteed to be same? Ethan Furman <ethan@stoneleaf.us> - 2012-07-26 14:03 -0700

csiph-web