collections.Counter(x)[x > 0] code example Example: import counter python from collections import Counter