Can a simple a==b 'hang' in and endless loop?
fuzzyman at gmail.com
Wed Jan 18 08:38:45 EST 2006
Claudio Grondi wrote:
> Thanks for the quick reply.
> I see, that I have overseen, that as Fredrik also stated, one can
> directly manipulate __eq__() as the easiest way to achieve what I
> To explain why I am not happy with it, I will try here to give some more
> background information. Sorry for not doing it directly, but as already
> stated I have forgot about the possibility to use __eq__().
> In Python the built in '==' operator (when not manipulated in own code)
> iterates over arrays (i.e. lists) doing many comparisons instead of
> expect '==' to compare the 'pointers' to the arrays and not to iterate
> over all elements of the lists.
In Python the equality operator ('==') compares values. For sequence
and mapping type objects this can be a (relatively) expensive
You are probably looking for the identity operator which just
(effectively) compares pointers ('is').
a is b
does more what you would expect.
This is a better system than the ones you describe. :-)
All the best,
> With the solution to the question above I intended to have an example of
> Python code which outcome is an endless loop and the problem causing it
> considering lists (as arrays) and the function of '==' operator.
More information about the Python-list