Semantics of ==

Andrew Bennetts andrew-pythonlist at
Wed Mar 17 01:23:45 CET 2004

On Tue, Mar 16, 2004 at 07:07:27PM -0500, John Roth wrote:
> "Axel Boldt" <axelboldt at> wrote in message
> news:40200384.0403161538.7407d9e2 at
> >   >>> s
> >   [1, [...]]
> >   >>> w
> >   [1, [1, [...]]]
> >   >>> s==w
> >   True
> I think the original True is a bug. It's getting confused
> by the recursion.

I don't think it's a bug.  In what sense are they unequal?  Both variables
are a sequence of two elements, the integer 1, and a sequence that's equal
to the outer sequence (i.e. s==s[1] is True, as Python will tell you).
Every element of the sequence s is equal to the corresponding element of the
sequence w, as far as I can see, even though there is infinite recursion.

Python is behaving exactly as I would expect it to.  (Although in the face
of such pathological data structures, I wouldn't mind terribly much if it


More information about the Python-list mailing list