Problem with sets and Unicode strings

Dennis Benzinger Dennis.Benzinger at gmx.net
Thu Jun 29 14:38:00 EDT 2006


Diez B. Roggisch wrote:
>> 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.
> [...]

Ok, I understand.
But isn't it a (minor) problem that using a set like this:

# -*- coding: UTF-8 -*-

FIELDS_SET = set(("Fächer", ))


print u"Fächer" in FIELDS_SET
print u"Fächer" == "Fächer"


shadows the error of not setting sys.defaultencoding()?


Dennis



More information about the Python-list mailing list