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

Mike Meyer mwm at mired.org
Fri Nov 25 00:07:47 CET 2005

"Martin v. Löwis" <martin at v.loewis.de> writes:
> Mike Meyer wrote:
>>>I trusted the doco which defines a set as "an unordered collection of
>>>immutable values" (http://docs.python.org/lib/types-set.html).
>> If the hash changes, you've screwed up the set. What it really should
>> say is "collection of objects with fixed hashes", or words to that
>> effect. Do you want to file a PR on this?
> It's more than that: you really mean "hashable values", where "hashable"
> does not just imply that the hash value is fixed, but also that the
> equal objects hash same.

I would have phrased it as "identical" instead of equal. Sets should
hold unique elements, where "unique" depends on the use at hand. For
some uses, "==" might be appropriate. For others, "is" might be

Would you care to suggest an improved wording?

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