[Python-ideas] Counter comparison

Ethan Furman ethan at stoneleaf.us
Mon Nov 24 02:03:27 CET 2014


On 11/23/2014 04:04 PM, Steven D'Aprano wrote:
> On Sun, Nov 23, 2014 at 11:30:25AM -0800, Antony Lee wrote:
>>
>> My goal was very simply to check whether it was possible to remove a
>> multi-set of elements from another, without any counts going below 0 (as
>> should be the case for "natural" counters).
> 
> Do you mean this?
> 
> py> from collections import Counter
> py> c1 = Counter({'a': 5, 'b': 2})
> py> c2 = Counter({'a': 1, 'b': 4})
> py> c1 - c2
> Counter({'a': 4})

Um, how does that show that 'b' went below zero?

--
~Ethan~

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141123/28092660/attachment.sig>


More information about the Python-ideas mailing list