Why is dictionary.keys() a list and not a set?
Peter Hansen
peter at engcorp.com
Wed Nov 23 23:13:16 EST 2005
bonono at gmail.com wrote:
> 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.
>
> Are there other usage scenarios that would be benefit from this as the
> example given is not convincing for me.
As Jeff's reply emphasizes, the "examples" show tuples with *value* and
then *key*, not the other way around which is what .items() and
.itemitems() gives you.
Anyway, you didn't ask for good examples of use, just "why is it
guaranteed", and that's all I was showing you. Whether it was a good
idea might be an interesting discussion, but probably not a particularly
useful one given once again that it's unlikely this particular feature
could be undone now that code exists (we can assume) which is dependent
on it.
-Peter
More information about the Python-list
mailing list