I am trying to find a simple and fast way of counting the number of Objects in a list that match a criteria. e.g.
class Person: def __init__(self, Name, Age,
I found that using a list comprehension and getting its length was faster than using sum().
sum()
According to my tests...
len([p for p in PeopleList if p.Gender == 'F'])
...runs 1.59 times as fast as...
sum(p.Gender == "F" for p in PeopleList)