testing two lists for equality

Raymond Hettinger vze4rx4y at verizon.net
Fri Jun 20 00:54:57 EDT 2003


> > If x and y are both lists (or tuples), is the expression
> >
> > (x == y)
> >
> > true if and only if len(x) = len(y) and all of the corresponding
> > elements in x and y are the same?
> >
> > I did not see this behavior documented in "Python Essential
> > Reference", but it makes sense and agrees with a few experiments I
> > did.
>
> http://python.org/doc/current/ref/comparisons.html might help.
>
> It basically implies what you said above, if you take "lexicographically"
> to mean something like "item by item".

Do you think docs should be changed from:

            Tuples and lists are compared lexicographically using
            comparison of corresponding items.

To:
            ... compared by sequentially comparing corresponding items.

Or something like:

           ...compared sequentially using comparison of corresponding items


Raymond Hettinger






More information about the Python-list mailing list