Is there a better way to count the number of elements for which the predicate function is true, other than this:
PredCount[lst_, pred_] := Length@Select[lst, pred];
I’m asking because it seems inefficient to construct a subset of lst with Select[], and because Count[] only works with patterns. In my use case, the function PredCount is called many times with a large lst.
You can often do this by turning your predicate into a pattern with a condition. For example:
would count the number of elements in list which are greater than 5.