On 07/11/2014 10:07 PM, Alan Bawden wrote:
Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> writes:

But perhaps we only care about changes in value, not type. NAN or no NAN,
list equality works fine:

py> data = [1.0, 2.0, float('nan'), 4.0]
py> old = data[:]
py> old == data  # No changes made yet, should return True
True

You lost me right here.  If list equality is determined by comparing
lists element-by-element, and the second element of old is _not_ equal
to the second element of data, then why should old and data be equal?

In fact, I find myself puzzled about exactly how list equality is
actually defined.  Consider:

   >>> a = float('nan')
   >>> x = [1, a, 9]
   >>> y = [1, a, 9.0]
   >>> x == y
   True

So is there some equality predicate where corresponding elements of x
and y are equal?

   >>> map(operator.eq, x, y)
   [True, False, True]

It's not "==".

   >>> map(operator.is_, x, y)
   [True, True, False]

And it's not "is".

class list:
    def __eq__(self, other):
        if len(self) != len(other):
            return False
        for this, that in zip(self, other):
             if this is that or this == that:
                 continue
             break
        else:
            return True
        return False

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to