MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/it4x8o/python_39_all_you_need_to_know/g5crwwu
r/Python • u/cheerfulboy • Sep 15 '20
204 comments sorted by
View all comments
Show parent comments
19
Set union isn't always commutative either:
>>> class A: ... def __init__(self, x, y): ... self.x, self.y = x, y ... def __eq__(self, other): ... return self.x == other.x if isinstance(other, A) else NotImplemented ... def __hash__(self): ... return hash(self.x) ... def __repr__(self): ... return f'A({self.x}, {self.y})' ... >>> {A(0, 0)} | {A(0, 1)} {A(0, 0)} >>> {A(0, 1)} | {A(0, 0)} {A(0, 1)}
12 u/scruffie Sep 15 '20 However, that's commutative with respect to the equality you defined, which is all we can expect. 1 u/ianliu88 Sep 16 '20 Well, I guess if you define dictionary equality by their keys, then the operation would be commutative, but that's generally not the case.
12
However, that's commutative with respect to the equality you defined, which is all we can expect.
1
Well, I guess if you define dictionary equality by their keys, then the operation would be commutative, but that's generally not the case.
19
u/bakery2k Sep 15 '20
Set union isn't always commutative either: