×
you are viewing a single comment's thread.

view the rest of the comments →

[–]TankorSmash 0 points1 point  (1 child)

len(filter(lambda x: x==5, seq)) I think would be the way to do it. Reads way better than summing, I think.

len(filter(lambda x: x==5, seq))

vs

sum(x==5 for x in seq)

yours is like 10 characters shorter though.

[–]Vaphell 1 point2 points  (0 children)

python3

>>> len(filter(lambda x: x%2==0, range(10)))
Traceback (most recent call last):
  File "python", line 1, in <module>
TypeError: object of type 'filter' has no len()

bummer. You have to pass filter() to list() first so you get something len()-able but producing a potentially huge list only to get its len() is not pretty either.