[Python-ideas] Counter comparison

Steven D'Aprano steve at pearwood.info
Mon Nov 24 02:20:09 CET 2014


On Sun, Nov 23, 2014 at 05:03:27PM -0800, Ethan Furman wrote:
> 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?

It doesn't, which is the point. Antony asked for removal WITHOUT counts 
going below zero.



-- 
Steve


More information about the Python-ideas mailing list