468,284 Members | 1,452 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,284 developers. It's quick & easy.

d.keys() and d.values()

Hi,

is it guaranteed that dict(zip(d.keys(), d.values())) == d?
In words, do .keys() and .values() always have the same order? Is
it safe to rely on this?

yours,
Gerrit.

--
279. If any one by a male or female slave, and a third party claim it,
the seller is liable for the claim.
-- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
http://www.sp.nl/

Jul 18 '05 #1
1 5134
Gerrit Holl wrote:
Hi,

is it guaranteed that dict(zip(d.keys(), d.values())) == d?
In words, do .keys() and .values() always have the same order? Is
it safe to rely on this?


It says so in the docs.

http://www.python.org/doc/current/lib/typesmapping.html

(3) "Keys and values are listed in random order. If keys() and values()
are called with no intervening modifications to the dictionary, the two
lists will directly correspond. This allows the creation of (value, key)
pairs using zip(): "pairs = zip(a.values(), a.keys())". "
regards Max M

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Steven Bethard | last post: by
2 posts views Thread by Pekka | last post: by
90 posts views Thread by Christoph Zwerschke | last post: by
7 posts views Thread by ProvoWallis | last post: by
22 posts views Thread by bearophileHUGS | last post: by
2 posts views Thread by The.Relinator | last post: by
13 posts views Thread by Nader | last post: by
12 posts views Thread by Florian Brucker | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.