3 ms·
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 callb
by seemslegit 7y ago
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
- anonymoushn 7y agoNote that a | b is already a disaster if you try to use subclasses of set. In python 2.7, iirc it would return a set of a's type but without calling the constructor. In python 3 it seems to return a set (not the type of a or the type of b).
- CameronNemo 7y agoNot sure about the set operator, but this operator is meant to handle subclasses better than the status quo.
- mdrachuk 7y agoWow, one more point for python 3. Just override ‘__and__’ in your whatever class to replace default return. Pretty explicit in my book.
- orf 7y agoIt’s also really expensive. This new operator works with any Mapping type without needing silly hacks.