[Python-ideas] Counter comparison

MRAB python at mrabarnett.plus.com
Sat Nov 22 01:27:59 CET 2014


On 2014-11-21 23:55, Antony Lee wrote:
> As Counter objects effectively behave like multi-sets, it seems
> reasonable to overload <, <=, >, >= as for set objects to check whether
> a Counter is a sub/super-set of another Counter:
>
> c < d  <===>  all(c[k] < d[k] for k in c)
>
> Thoughts?
>
More correctly, it would be:

     all(c[k] < d[k] for k in set(c) | set(d))



More information about the Python-ideas mailing list