A comparable counter for Python
In this post, we’re going to investigate Python’s powerful collections.Counter
class, and how we can use it to, well, count stuff.
We’ll find that comparisons with other Counter
instances are supported, but unintuitive, and that scalar comparisons are not supported.
We’ll take a plunge into special methods, a somewhat low-level concept that enables, among other things, comparisons between objects.
With this knowledge, we’ll build a ComparableCounter
class that can we can use to apply a threshold to the actual value-counts and filter a Counter
in a more intuitive approach!