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

2018-04-15 Thread Peter Norvig
, v) in self.items()) > > On Sun, Apr 15, 2018 at 5:05 PM, Peter Norvig <pe...@norvig.com> wrote: > >> For most types that implement __add__, `x + x` is equal to `2 * x`. >> >> That is true for all numbers, list, tuple, str, timedelta, etc. -- but >> not for collections.Cou

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

2018-04-15 Thread Peter Norvig
For most types that implement __add__, `x + x` is equal to `2 * x`. That is true for all numbers, list, tuple, str, timedelta, etc. -- but not for collections.Counter. I can add two Counters, but I can't multiply one by a scalar. That seems like an oversight. It would be worthwhile to implement

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

2018-04-15 Thread Peter Norvig
es/blob/master/ipynb/Probability.ipynb a bit, and now I no longer need a `normalize` function.) On Sun, Apr 15, 2018 at 5:06 PM Raymond Hettinger < raymond.hettin...@gmail.com> wrote: > > > > On Apr 15, 2018, at 2:05 PM, Peter Norvig <pe...@norvig.com> wrote: > > > > For most

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

2018-04-15 Thread Peter Norvig
On Sun, Apr 15, 2018 at 8:39 PM Raymond Hettinger < raymond.hettin...@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

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

2018-04-15 Thread Peter Norvig
Raymond Hettinger < raymond.hettin...@gmail.com> wrote: > > > > On Apr 15, 2018, at 9:04 PM, Peter Norvig <pe...@norvig.com> wrote: > > > > it would be a bit weird and disorienting for the arithmetic operator