Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   d.keys() and d.values() (http://www.velocityreviews.com/forums/t318790-d-keys-and-d-values.html)

Gerrit Holl 06-24-2003 10:03 AM

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/


Max M 06-24-2003 12:53 PM

Re: d.keys() and d.values()
 
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



All times are GMT. The time now is 07:34 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.