[Python-ideas] PEP: Dict addition and subtraction
pythonchb at gmail.com
Thu Mar 21 22:19:06 EDT 2019
> https://docs.python.org/3.8/library/collections.html has some
> examples using collections.Counter, which is clearly described
> as being a subclass of dict. Amongst the examples:
> c + d # add two counters together: c[x] + d[x]
> That's the + operator operating on two dicts (don't make me
> quote the Liskov Substitution Principle), but doing something
> really different than the base operator.
> So if I know that c and d (or worse, that one of them) is a
> dict, then interpreting c + d becomes much more interesting,
Killing a use of a common operator with a very common built in data type
because the operator is used in a different way by a specialized object in
the stdlib seems a bit backwards to me.
Frankly, I think considering Counter as a dict subclass is the mistake
here, even if it is true.
Christopher Barker, PhD
Python Language Consulting
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas