Try using a method valuesin a dictionary (which returns a generator in Python 3.x), repeating each value and summing if it is greater than 0 (or regardless of your state):
In [1]: d = {'one': 1, 'two': 2, 'twenty': 20, 'negative 4': -4}
In [2]: sum(v for v in d.values() if v > 0)
Out[2]: 23
source
share