Dictionary .keys() and .values() should return a set [with Python 3000 in mind]

Piet van Oostrum piet at cs.uu.nl
Mon Jul 3 11:00:56 EDT 2006


>>>>> "Paddy" <paddy3118 at netscape.net> (P) wrote:

>P> vatamane at gmail.com wrote:
>>> This has been bothering me for a while. Just want to find out if it
>>> just me or perhaps others have thought of this too: Why shouldn't the
>>> keyset of a dictionary be represented as a set instead of a list?

>P> I think the order of the items returned by keys() and values() are
>P> related. I decided on a short  empirical test:

yes, it is documented that their order is related. In fact 
d.items() == zip(d.keys(), d.values())
This wouldn't work with sets instead of lists.
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list