By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

d.keys() and d.values()

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.