l = [1, 4, 6, 7, 30, 2]

def my_condition(x):
    return x > 5 and x < 20
print(sum(1 for x in l if my_condition(x)))
print(sum(1 for x in range(1000000) if my_condition(x)))
python: get number of items from list(sequence) with certain condition