How does a python programmer check if any value of a dictionary matches a condition (is greater than 0
in my case). I'm looking for the most "pythonic" way that has minimal performance-impact.
my dictionary:
pairs = { 'word1':0, 'word2':0, 'word3':2000, 'word4':64, 'word5':0, 'wordn':8 }
I used these 2 (monstrous?) methods so far.
1:
options = pairs.values() # extract values
for i in options:
if i > 0:
return True
return False
2:
options = sorted(pairs.items(), key=lambda e: e[1], reverse=True) # rank from max to min
if options[0][1] > 0:
return True
else:
return False