Python: Sum values in a dictionary based on condition
python, python-3.x
Solution
Try using the `values` method on the dictionary (which returns a generator in Python 3.x), iterating through each value and summing if it is greater than 0 (or whatever your condition is):
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
Problem
I have a dictionary that has `Key:Values.` The values are integers. I would like to get a sum of the values based on a condition...say all values > 0 (i.e). I've tried few variations, but nothing seems to work unfortunately.