Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25850
| From | Henrik Faber <hfaber@invalid.net> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | dict: keys() and values() order guaranteed to be same? |
| Date | 2012-07-23 13:23 +0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <jujc6j$rk5$1@speranza.aioe.org> (permalink) |
Hi group,
I have a question of which I'm unsure if the specification guarantees
it. With an arbitrary dictionaty d, are d.keys() and d.values()
guaraneed to be in the same order? I.e. what I mean is:
# For all dictionaries d:
assert({ list(d.keys())[i]: list(d.values())[i] for i in range(len(d)) }
== d)
I'm curious if it's allowed because in a special case it would make for
a nice shortcut and clean code. I think however that the implementation
may chose not to have them in the same order necessarily -- then I'd
obviously avoid relying on it.
Best regards,
Joe
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll 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