[Python-ideas] collections.Counter multiplication

David Mertz mertz at gnosis.cx
Wed May 29 22:21:56 CEST 2013


That "intuitive" behavior certainly wouldn't have been my first--or second
guess--on seeing the syntax.


On Wed, May 29, 2013 at 1:17 PM, James K <jamylak at gmail.com> wrote:

> It should work like this
>
>     >>> from collections import Counter
>     >>> Counter({'a': 1, 'b': 2}) * 2 # scalar
>     Counter({'b': 4, 'a': 2})
>     >>> Counter({'a': 1, 'b': 2}) * Counter({'c': 1, 'b': 2}) # multiplies
> matching keys
>     Counter({'b': 4})
>
>
> 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.
>
>
> On Thu, May 30, 2013 at 12:29 AM, Ned Batchelder <ned at nedbatchelder.com>wrote:
>
>>  On 5/29/2013 1:27 AM, James K wrote:
>>
>> Can we add a multiplication feature to collections.Counter, I don't see
>> why not.
>>
>>
>> James, welcome to the list.  To get an idea accepted, you have to do a
>> few things:
>>
>> 1) Explain the idea fully.  I don't understand what "a multiplication
>> feature" would do.
>> 2) Explain why the idea is useful to enough people that it should be
>> added to the standard library.
>>
>> 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.
>>
>> Discussing these things doesn't often result in a change to Python, but
>> does often lead to useful discussion.
>>
>> --Ned.
>>
>>
>>
>> _______________________________________________
>> Python-ideas mailing listPython-ideas at python.orghttp://mail.python.org/mailman/listinfo/python-ideas
>>
>>
>>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>


-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130529/e0bc74a2/attachment-0001.html>


More information about the Python-ideas mailing list