Unexpected behaviour from the 'in' operator
aleax at aleax.it
Mon Feb 24 11:06:19 CET 2003
Rene Pijlman wrote:
> Andrew Bennetts:
> [testing for identity instead of equality]
>>On the other hand, it could be genuinely useful if the objects
>>had very slow equality operators...
> If this is true I guess the equality operator could be optimized
> to first check for identity, and only test non-identical objects
> for equality.
Of course -- it's up to you to do this in your __eq__ or
__cmp__ methods, of course (Python doesn't FORCE you to have
"a==a" if for some weird reason you don't want to...!-).
More information about the Python-list