Dictionary union (PEP 584) is merged
github.com
Dictionary union (PEP 584) is merged
1–10 of 87 posts
Re: Dictionary union (PEP 584) is merged
#2Re: Dictionary union (PEP 584) is merged
#3The PEP document describing the feature: https://www.python.org/dev/peps/pep-0584/
> 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
#4Re: Dictionary union (PEP 584) is merged
#5I 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
#6I 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.
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 usedRe: Dictionary union (PEP 584) is merged
#7Re: Dictionary union (PEP 584) is merged
#8 {**d1, **d2}
is very natural if you also write javascript where their spread operator looks like: {...d1, ...d2}