"a in b" calls a.__cmp__, why?

Gerrit Holl gerrit at nl.linux.org
Sat Jun 21 17:31:34 EDT 2003


Terry Reedy wrote:
> "Gerrit Holl" <gerrit at nl.linux.org> wrote in message
> news:mailman.1056224677.5103.python-list at python.org...
> > Why does a container-sequence's __contains__ call obj.__cmp__?
> 
> Because 'in' is defined by equality, as determined by comparison
> returning 0 or not ,  and not by identity.

Ah, thanks... I'll override __eq__ then to compare by equality.

> If you want identity in-ness, either program the search yourself or
> use a list  (or dict/set) of ids and search for id(item) in idlist.
> 
> If your list is long (enough) and repeatedly searched, sorting and
> using binsearch or making a set or dict for hash access will be
> faster.

I will try that.
Thanks!

yours,
Gerrit.

-- 
168. If a man wish to put his son out of his house, and declare before
the judge: "I want to put my son out," then the judge shall examine into
his reasons. If the son be guilty of no great fault, for which he can be
rightfully put out, the father shall not put him out.
        -- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list