Are there any list comparison optimizations in Python?

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Mon Nov 19 15:07:42 EST 2001


On Thu, 15 Nov 2001 21:18:10 -0500, Peter Hansen <peter at engcorp.com> wrote:
>
>Well, you just pointed out one case, which is probably enough reason
>not to add a special case to the language itself.

Should this one case itself be considered a special case?  

>Other practical uses I can think of start with using it during
>testing, to verify that a particular code path will actually
>work if it is taken, or for troubleshooting a particularly
>unclear problem which involves comparisons.

What would such examples look like?  I can only think of cases where the
problems are caused exactly by (a is b) and (a!=b) both being true.  They
would dissappear if (a is b) implies (a==b).

A good example might be something that uses == for a task that is
semantically different from the concept "equal", yet it still needs to be
spelt as == to utilize other facilities that rely on it.

>Not that it should necessarily matter.  If == is defined
>as using __cmp__, then for consistency (principle of 
>least surprise) one should be able to rely on that definition.

Yes, if that is the definition.  But the definition has not always been this
way.  The question is whether another definition (which happens to be an
older definition) is better.

Huaiyu



More information about the Python-list mailing list