<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>On May 29, 2013, at 20:31, David Mertz <<a href="mailto:mertz@gnosis.cx">mertz@gnosis.cx</a>> wrote:</div><div><br></div><blockquote type="cite"><div><div dir="ltr"><div><div><div><div>Well... I actually *did* implement it a few notes up-thread, it's not merely simple, but actual.</div></div></div></div></div></div></blockquote><div><br></div><div>OK, so the OP can just copy and paste.</div><div><br></div><div>I think I'd use numbers.Integral and collections.abc.Mapping rather than int and Counter. And maybe take any Container as a counter with the value 1 for each key, given that Counter is intended to work as a multiset.</div><div><br></div><div>Also, I think the one-liner dict comprehension implementation is simpler than the explicit loop around setitem.</div><div><br></div><div>And I think if you have mult you'll probably want imult as well. </div><div><br></div><div>But bikeshedding aside, your implementation should be more than enough for the OP.</div><br><blockquote type="cite"><div><div dir="ltr"><div><div><div><div>  If you really want, you can privately substitute my:<br><br></div>   class MyCounter(Counter): ...<br>
<br></div>with:<br><br></div>   class Counter(Counter): ...<br><br></div>Of course, I don't *recommend* doing that. :-)<br></div></div></blockquote><div><br></div><div>Well, given that it will be in a separate module if the OP puts it on PyPI, I don't see any downside to giving it the same name.</div><br><blockquote type="cite"><div><div dir="ltr"><div><div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 29, 2013 at 6:47 PM, Andrew Barnert <span dir="ltr"><<a href="mailto:abarnert@yahoo.com" target="_blank">abarnert@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><div>Given how simple this would be to implement, I think the obvious way forward is to write an implementation, put it on PyPI, and give it time to see if it gets any traction. If enough people use it, it can be easily added to the stdlib later.</div>
<div><br></div><div>(IIRC, there's a project named something like more-collections that has OrderedSet, OrderedDefaultDict, etc., so you could submit this new class as a patch to that project instead of creating a new one, but that doesn't make too much difference.)<br>
</div><div><br></div><div>If you don't know how to write the implementation yourself, just ask and someone will write it for you.</div><br>Sent from a random iPhone</div><div><div class="h5"><div><br>On May 29, 2013, at 13:17, James K <<a href="mailto:jamylak@gmail.com" target="_blank">jamylak@gmail.com</a>> wrote:<br>
<br></div><blockquote type="cite"><div><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>
    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>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Python-ideas mailing list</span><br><span><a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a></span><br>
<span><a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a></span><br></div></blockquote></div></div></div><br>_______________________________________________<br>

Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>
advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br>
</div></div></div></div></div></div>
</div></blockquote></body></html>