Semantics of ==

Axel Boldt axelboldt at
Thu Mar 25 14:32:58 CET 2004

Erik Max Francis <max at> wrote
> Axel Boldt wrote:
> > ...and then it can run into an infinite loop. I explained that for the
> > example s==w in the part you deleted. The recursion does not always
> > have a base case; the rule does not always give a definite truth
> > value.
> But the == operator doesn't run into an infinite loop, so this is much
> ado about nothing.

Well, it's precisely the point: the definition of list equality given
in the language reference is circular, but the implementation of ==
clearly is not, so the two don't coincide. I'm trying to understand
what the precise semantics of == for lists is. Right now, if you give
me two list definitions, I don't feel confident to determine whether
they are equal or not, without starting python.

> > I.e., I'm interesting in a function val : lists -> strings with the
> > property val(l1) == val(l2) iff l1 == l2. That would also considerably
> > clarify the semantics of == for lists, which I still don't understand.
> Why are you interested in such a function?

Like I said, it would clarify the semantics of == for lists. Another
use would be to hash on values of lists. (The FAQ 4.18 recommends to
first convert a list to a tuple and hash on that, but of course that
doesn't work in general. The ListWrapper class in 4.18 also works only
for simple minded lists.)


More information about the Python-list mailing list