Why is dictionary.keys() a list and not a set?

Mike Meyer mwm at mired.org
Wed Nov 23 23:27:50 EST 2005


"bonono at gmail.com" <bonono at gmail.com> writes:
> Which is also my initial puzzle, items() and iteritems() already gives
> you the tuples, why such gurantee or the others ? Doesn't that violate
> the general idiom that if we can do certain thing in one way, there
> better be one and only one way.

Backwards compatability. The guarantee on the order of keys() and
values() predates items() (and iteritems()). You can't remove the
guarantee without potentially breaking old code, and that's Not Done -
at least not to code that wasn't broken to begin with.

Maybe dropping the guarantee should be considered for P3K, on the off
chance that either keys or values could be made faster at some point
in the future. But I don't see it as a big deal.

   <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list