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


Groups > comp.lang.python > #25854

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

From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: dict: keys() and values() order guaranteed to be same?
Date 2012-07-23 13:58 +0200
References <jujc6j$rk5$1@speranza.aioe.org> <500D383A.9090500@phihag.de>
Newsgroups comp.lang.python
Message-ID <mailman.2462.1343044733.4697.python-list@python.org> (permalink)

Show all headers | View raw


Philipp Hagemeister, 23.07.2012 13:40:
> 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.
> 
> [1] http://docs.python.org/library/stdtypes.html#dict.items

Interesting. I wonder if other implementations like Jython and PyPy really
adhere to this official guarantee. At least Jython has the same paragraph
in its documentation and I would expect that PyPy follows it as well.

http://www.jython.org/docs/library/stdtypes.html#mapping-types-dict

Maybe this guarantee is just easy enough to build on the given
implementation details of a platform that it's a common property. Iteration
over data structures should tend to be deterministic, after all.

Stefan

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