Live data from Hacker News

Dictionary union (PEP 584) is merged

github.com

1–10 of 87 posts

Re: Dictionary union (PEP 584) is merged

#3
post #2

The PEP document describing the feature: https://www.python.org/dev/peps/pep-0584/

> > Dict union will violate the Only One Way koan from the Zen.

> There is no such koan. "Only One Way" is a calumny about Python originating long ago from the Perl community.

Re: Dictionary union (PEP 584) is merged

#4
I wouldn't have thought about dict unpacking as a solution either but once suggested it seems satisfactory and I don't see how adding a new operator is more discoverable or natural than just putting this method in a more prominent place in the documentation.

Re: Dictionary union (PEP 584) is merged

#5

I wouldn't have thought about dict unpacking as a solution either but once suggested it seems satisfactory and I don't see how adding a new operator is more discoverable or natural than just putting this method in a more prominent place in the documentation.

Guido himself said he had forgotten about this trick and since it's syntactic sugar, it does not respect dict subclasses or other mappings.

Re: Dictionary union (PEP 584) is merged

#6
post #5

I wouldn't have thought about dict unpacking as a solution either but once suggested it seems satisfactory and I don't see how adding a new operator is more discoverable or natural than just putting this method in a more prominent place in the documentation.

Guido himself said he had forgotten about this trick and since it's syntactic sugar, it does not respect dict subclasses or other mappings.

imo

  defaultdict(callback,{**a,**b}) 
is more readable than a | b without knowing that a or b are defaultdicts and having to reason about which default callback will be used

Re: Dictionary union (PEP 584) is merged

#10
Yay! I was wishing for this feature just a few days ago. It's somewhat analogous to how sorted (since Python 2.4) frees us from having to tediously make copies of lists to sort them in place.
Post reply on HN