It seems that just using + as the operator was reject because it's: "Too specialised to be used as the default behavior." What does that mean? It works for lists, obviously lists don't need to worry about duplicated values, but it's kind non-intuitive that + won't work for dicts. It think many people view dicts and lists as the same general type of data structure.
>> It think many people view dicts and lists as the same general type of data structure.
The choice of the "|" operator for set union comes from bitwise operations: bitwise OR works as a union operator if you are using integers as bit vectors to represent sets of boolean attributes. And it was a common idiom back in the day when people used to program in C/assembly, using words as bit vectors was a common way to save memory. Hence "|" as set union is intuitive for people who are familiar with this applic…
I think the OR operator comes from set theory and has nothing to do with the low-level boolean flag fieldsets.
The choice of the "|" operator for set union comes from bitwise operations: bitwise OR works as a union operator if you are using integers as bit vectors to represent sets of boolean attributes. And it was a common idiom back in the day when people used to program in C/assembly, using words as bit vectors was a common way to save memory. Hence "|" as set union is intuitive for people who are familiar with this applic…
I think the OR operator comes from set theory and has nothing to do with the low-level boolean flag fieldsets.
I looked up set theory a couple of places (WP[1] and Britannica[2]) and didn't find any references of the OR operator in this context.. do you have a link?
I think the OR operator comes from set theory and has nothing to do with the low-level boolean flag fieldsets.
I looked up set theory a couple of places (WP[1] and Britannica[2]) and didn't find any references of the OR operator in this context.. do you have a link? [1] https://en.wikipedia.org/wiki/Algebra_of_sets [2] https://www.britannica.com/science/set-theory/Operations-on-...
The analogue of the OR operator in set theory is the union operator. People think of them as basically the same thing because of the correspondence between a property and the set of things with that property. If A is the property of being either B or C, then the set of the things that are A is the union of the set of things that are B and the set of things that are C.
That ship had long sailed with string formatting anyways.
F-strings are the one obvious way to do string formatting. There may be other ways, for legacy backwards compatibility reasons, but f-strings are the way to do string formatting.
Yes, unless a template is needed later. That's why the others continue to exist.
Fantastic. Especially glad they went with | over +, that’s always felt like the natural way I’ve wanted to do this. Looking forward to more set-like operators in the future!
Thank goodness sanity prevailed on the operator! We had a whole discussion on HN last time[1] about this, where I argued that dicts are logically subclasses of sets and therefore should share operators. When I saw this headline I accepted my fate of typing the "wrong" operator from now on and liking Python just a tiny bit less for the inconsistency. So glad they reconsidered. [1] https://news.ycombinator.com/item?id=…
Guido stated his preference to | and the pep was changed.
The best way to do dictionary union is already symbolic: {**d1, **d2} This provides a clearer symbolic notation for dictionaries analogous to what's already available with sets. FWIW the pep discusses what this would look like as a method vs an operator: https://www.python.org/dev/peps/pep-0584/#use-a-method
The best way for in my view is .union(), the new syntax additions are too cryptic.
Not sure what you're referring to because there is no "union" method/function. There is currently no non-symbolic built-in way to combine dictionaries in an expression.
You may be interested to read PEP 584's list of examples of all the real-world code the existence of this operator makes clearer: