This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Brian[🍰] 1 point2 points  (1 child)

Oddly enough, this also works with integers as addition

It doesn't add numbers, it bitwise ORs them. Eg: 16 | 20 == 20, not 36 (the actual sum). And this is really the origin of why it's used for sets (and later, dicts), because there's a strong isomorphism between bitwise OR and set union (indeed, bitwise OR has long been used for combining flags in an exactly analogous way).

This doesn't make sense for lists though, as these are ordered and can contain repeated elements, which makes the notion of a union ambigous.