
Oct. 21, 2019
2:38 a.m.
On 2019-10-21 02:29, Steven D'Aprano wrote:
On Mon, Oct 21, 2019 at 02:02:07AM +0100, MRAB wrote:
In the case of Counter, it supports both + and |.
The proposed operator will replace where there are matching keys. Which operator of Counter does that? Neither.
That's okay. That's what subclasses are for: to support specialised behaviour.
I've just realised why I prefer | over +: | is used with sets, which might overlap, so len(x | y) <= len(x) + len(y) + is used with lists and strings, which don't overlap, so len(x + y) == len(x) + len(y) On that basis, dicts are more like sets, IMHO.