3. Count matching items without a temporary list

When you only need a count, use a generator expression instead of building a temporary list first.

A generator expression keeps the pipeline focused on the count rather than on building an intermediate structure that will be discarded immediately. That is a small but common example of aligning the expression with the result you actually need.

3.1. Don’t do this

1nums = list(range(100))
2count = len([n for n in nums if n % 2 == 0])

3.2. Do this

1nums = list(range(100))
2count = sum(1 for n in nums if n % 2 == 0)