3 ms·
If you're going to go that route, I think this makes more sense: count_over_17 = [age > 17 for age in ages].count(True)
by nomel 3y ago
If you're going to go that route, I think this makes more sense:
count_over_17 = [age > 17 for age in ages].count(True)
- dragonwriter 3y agoFor a very large sequence traversing it to build a list and then traversing the list to do something you could do in one traversal without creating a list may be undesirable.
- nomel 3y agoIn a very large sequence, you would be using numpy. I assumed the purpose of their example was some sort of clarity, over `sum(age > 17 for age in ages)`, rather than performance.