On Fri, 22 Mar 2019 at 07:46, Terry Reedy <tjreedy@udel.edu> wrote:
On 3/22/2019 12:53 AM, Steven D'Aprano wrote:
If a+b already worked for dicts, would you still prefer {**a, **b}?
Example: {**sys.modules, **globals()}
Aside from the fact that I can patch *and* backport to 3.7 *now*, I think so. The latter clearly (to me) maps mappings to a dict.
How about if it were spelled a|b?
As in sys.modules | globals() or (sys.modules | globals())? Closer.
Adding a comment here because it's new information (to me, about my subjective preferences, at least). I accept that it's "just" more comment on the whole point about what people subjectively prefer, but at some point the *amount* of subjective preference has to be considered, not everything can be decided purely on objective grounds, so hopefully it's still a useful data point. This is probably the first example of "real world" code written using {**d1, **d2} notation alongside d1+d2 and d1|d2 notation that has caught my attention (I've been skimming, I may have missed some). And I have to say that I find {**d1, **d2} (when used with real values rather than d1 and d2) *far* more obvious in context than either of the operator notations. I wouldn't have expected that - my intuition was that {**d1, **d2} is too punctuation-heavy and "perlish". But surprisingly that's not the case at all. If I ever needed side effect free dictionary merging as an expression, I'd now definitely prefer {**d1, **d2} to any operator form. Paul