Having:
class Foo:
def __init__(self, a, b):
self.a = a
self.b = b
and a list like:
l = [Foo(1, 2), Foo(1, 3), Foo(1, 4), Foo(1, 10)]
If I want to count the number of objects having a == 1, I do
>>> count_a = len([o for o in l if o.a == 1])
>>> assert count_a == 4
It is not a function in the library to allow me to execute somthing like:
>>> from operator import attrgetter
>>> count(l, key=attrgetter('a'))
4