4 ms·
I wonder why set operations were never supported for dictionaries. a = b | c makes perfect sense, vs: a = b.copy() a.update(c)
by kbd 11y ago
I wonder why set operations were never supported for dictionaries.
a = b | c
makes perfect sense, vs:
a = b.copy()
a.update(c)
- JoshTriplett 11y agob|c for sets is commutative; b|c for dictionaries is not. | is not strictly required to commute, but a | operator that does not commute is surprising behavior, and Python doesn't favor surprising behavior.
- kbd 11y agoThanks! That's exactly what I figured was the reason. Personally I'd have gone for the practicality beats purity side of things here, but oh well.
- azernik 11y agoI think this is a practicality concern; specifically, with regards to the UI, and following the rule of least surprise to keep user (i.e. programmer) confusion down.