Q:

Most Pythonic Condition Counter

I have a list, and need to create a count of how many times a condition is met.  Is it more pythonic to do this:
cnt = sum([1 for s in a_list if some_condition])

or is this more pythonic:
cnt = 0
  for s in a_list:
    if (some_condition):
      cnt += 1

A:

Neither.
Use the first one but without creating an unnecessary list in memory:
cnt = sum(1 for s in a_list if some_condition)

A:

Use the fact, that True used as an integer is 1:
cnt = sum(some_condition(s) for s in a_list)

A:

You can do it more simply:
cnt = sum(map(condition_func, a_list))

That assumes condition_func is some sort of function that turns an item in the list into True or False.

