<div dir="ltr"><div>It should work like this<br><br> >>> from collections import Counter<br> >>> Counter({'a': 1, 'b': 2}) * 2 # scalar </div><div> Counter({'b': 4, 'a': 2})</div>
<div> >>> Counter({'a': 1, 'b': 2}) * Counter({'c': 1, 'b': 2}) # multiplies matching keys</div><div> Counter({'b': 4})<br><br><br></div><div class="gmail_extra">This is intuitive behavior and therefore should be added. I am unsure about division as dividing by a non-existing key would be a division by 0, although division by a scalar is straightforward.<br>
<br><div class="gmail_quote">On Thu, May 30, 2013 at 12:29 AM, Ned Batchelder <span dir="ltr"><<a href="mailto:ned@nedbatchelder.com" target="_blank">ned@nedbatchelder.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF"><div class="im">
On 5/29/2013 1:27 AM, James K wrote:<br>
<blockquote type="cite">
<div dir="ltr">Can we add a multiplication feature to
collections.Counter, I don't see why not.</div>
</blockquote>
<br></div>
James, welcome to the list. To get an idea accepted, you have to do
a few things:<br>
<br>
1) Explain the idea fully. I don't understand what "a
multiplication feature" would do.<br>
2) Explain why the idea is useful to enough people that it should be
added to the standard library.<br>
<br>
These two criteria are not easy to meet. Sometimes an idea seems
popular, but it turns out that different people want it to behave
differently, or differently at different times (see the discussion
about an itertools.chunked feature). Sometimes an idea is
straightforward enough to describe, but is useful to too few people
to justify adding it to the standard library.<br>
<br>
Discussing these things doesn't often result in a change to Python,
but does often lead to useful discussion.<br>
<br>
--Ned.<br>
<br>
<blockquote type="cite">
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
Python-ideas mailing list
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a>
</pre>
</blockquote>
<br>
</div>
</blockquote></div><br></div></div>