[Python-ideas] collections.Counter should implement __mul__, __rmul__

Peter Norvig peter at norvig.com
Mon Apr 16 00:04:00 EDT 2018


On Sun, Apr 15, 2018 at 8:39 PM Raymond Hettinger <
raymond.hettinger at gmail.com> wrote:

> FWIW, Counter is explicitly documented to support the four multiset-style
> mathematical operations discussed in Knuth TAOCP Volume II section 4.6.3
> exercise 19:
>

Wow, I never noticed "&" and "|" -- I guess when I got to "Common patterns
for working with" in the documentation, I figured that there wouldn't be
any new methods introduced after that and I stopped reading.

>
> it would be a bit weird and disorienting for the arithmetic operators to
> have two different signatures:
>
>     <counter> += <counter>
>     <counter> -= <counter>
>     <counter> *= <scalar>
>     <counter> /= <scalar>
>

Is it weird and disorienting to have:

<str> += <str>
<str> *= <scalar>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180416/f3b81111/attachment.html>


More information about the Python-ideas mailing list