Proposal: === and !=== operators

Alan Bawden alan at
Sat Jul 12 07:07:28 CEST 2014

Steven D'Aprano <steve+comp.lang.python at> 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

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".

Alan Bawden

More information about the Python-list mailing list