checking if an object IS in a list

Terry Reedy tjreedy at udel.edu
Fri Jul 18 22:49:21 CEST 2008



Peter Otten wrote:

>> So, precisely, you mean that if hash(a) != hash(b), a and b are
>> considered distinct, and else [ie. if hash(a) == hash(b)], a and b are
>> the same if and only if a == b ?
> 
> Correct for set, dict. For lists etc. the hash doesn't matter:

Since CPython saves strings hashes as part of the string object (last I 
read, as part of internal string caching), it does something similar. 
Compare lengths, then hashes, then C array.




More information about the Python-list mailing list