I'd add an one line conditional counting:
amounts = [2, 24, 88, 32, 1, 6, 88, 10, 15, 34] greater_than_15 = sum(1 for amount in amounts if amount > 15)
Since this creates a generator and then sums over it, it avoids creating an intermediary copy of the items in the list that satisfy the condition.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'd add an one line conditional counting:
Since this creates a generator and then sums over it, it avoids creating an intermediary copy of the items in the list that satisfy the condition.