Why is dictionary.keys() a list and not a set?
bonono at gmail.com
bonono at gmail.com
Wed Nov 23 23:43:31 EST 2005
Mike Meyer wrote:
> "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.
>
Thanks, that explain it. I don't know that there was no
items()/iteritems() in earlier version.
More information about the Python-list
mailing list