An oddity in list comparison and element assignment

michael.f.ellis at gmail.com michael.f.ellis at gmail.com
Thu Jun 1 12:00:18 EDT 2006


Hi Alex,
With all due respect to your well-deserved standing in the Python
community, I'm not convinced that equality shouldn't imply invariance
under identical operations.

Perhaps the most fundamental notion is mathematics is that the left and
right sides of an equation remain identical after any operation applied
to both sides.  Our experience of the physical world is similar.  If I
make identical modifications to the engines of two identical
automobiles, I expect the difference in performance to be identical.
If my expectation is met, I would assert that either the two vehicles
were not identical to begin with or that my modifications were not
performed identically.

As to containers,  would you say that envelope containing five $100
bills is the same as an envelope containing a single $100 bill and 4
xerox copies of it? If so, I'd like to engage in some envelope
exchanges with you :-)

As I see it, reference copying is a very useful performance and memory
optimization.  But I don't think it should undermine the validity of
assert(a==b) as a predictor of invariance under identical operations.

Cheers,
Mike Ellis


Alex Martelli wrote:
> <michael.f.ellis at gmail.com> wrote:
> Wrong; equality does not imply any check on identity.  You can consider
> the definition of "list A equals list B" as:
>
> -- len(A) == len(B), AND,
> -- for each valid index i, A[i] == B[i]
>
> This is an extremely natural definition of "equality" for containers:
> "they have EQUAL items" [[in the same order, for containers for which
> order is relevant]].  Nowhere in this extremely natural definition does
> the IDENTITY of the items come into play.




More information about the Python-list mailing list