Counting positive integer elements in a list with Python list comprehensions
If you want to reduce the amount of memory, you can avoid generating a temporary list by using a generator: sum(x > 0 for x in frequencies) This works because bool is a subclass of int: >>> isinstance(True,int) True and True‘s value is 1: >>> True==1 True However, as Joe Golton points out in the … Read more