3 ms·
While I agree with you, I will note that even set union in Python is not commutative. a | b should equal b | a in the sense of __eq__, but the actual objects in
by zwegner 8y ago
While I agree with you, I will note that even set union in Python is not commutative. a | b should equal b | a in the sense of __eq__, but the actual objects in the result set depend on the order of the arguments (and in the opposite way from dict + dict). This happens with objects that are distinct but compare/hash equally (x is not y and x == y). Whether that actually matters for any useful program is another story...
Dumb program to illustrate this point:
class Dummy:
def __init__(self, value): self.value = value
def __repr__(self): return 'Dummy(%s)' % self.value
def __hash__(self): return 0
def __eq__(self, other): return True
a = {Dummy(0)}
b = {Dummy(1)}
print(a | b)
print(b | a)
print(a | b == b | a)