Problem with sets and Unicode strings

Diez B. Roggisch deets at nospam.web.de
Wed Jun 28 13:04:19 EDT 2006


> But I'd say that it's not intuitive that for sets x in y can be false
> (without raising an exception!) while the doing the same with a tuple
> raises an exception. Where is this difference documented?

2.3.7 Set Types -- set, frozenset

...

Set elements are like dictionary keys; they need to define both __hash__ and
__eq__ methods.
...

And it has to hold that

a == b => hash(a) == hash(b)

but NOT

hash(a) == hash(b) => a == b

Thus if the hashes vary, the set doesn't bother to actually compare the
values.

Diez



More information about the Python-list mailing list