how to test for atomicity/mutability/hashability?

kj no.email at please.post
Thu Oct 7 15:13:28 EDT 2010





I want to implement a test t() that will return True if its two
arguments are "completely" different.  By this I mean that they
don't share any "non-atomic" component.  E.g., if

a = [0, 1]
b = [0, 1]
c = [2, 3]
d = [2, 3]

A = (a, c, 0)
B = (a, d, 1)
C = (b, d, 0)

The desired test t() would yield:

t(A, B) -> False (A and B share the mutable component a)
t(A, C) -> True (a =!= c, b =!= d, and 0 is not mutable)
t(B, C) -> False (B and C share the mutable component d)

(=!= is shorthand with "is not identical to".)

It would facilitate the implementation of t() to have a simple test
for mutability.  Is there one?

Thanks!

~kj



More information about the Python-list mailing list