Return All The Keys (as Set) From Num_dict That Have Value Greater Than Or Equal To Min_cutoff
Parameters num_dict: dictionary all values are numeric min_cutoff: float Compare with the num_dict values. Return all keys where their values >= min_cutoff. My dictionary is
Solution 1:
defkeys_get_cutoff(dict, min_value):
return [key for key indict.keys() ifdict[key] >= min_value]
Solution 2:
Using list comprehension. see more details about list comprehension
Ex.
num_dict = {'Denver': 200, 'Houston': 100, 'NOLA':50}
min_cutoff = 51
num_dict_keys = [k for k, v in num_dict.items() if v >= min_cutoff ]
print(num_dict_keys)
O/P:
['Denver', 'Houston']
Post a Comment for "Return All The Keys (as Set) From Num_dict That Have Value Greater Than Or Equal To Min_cutoff"