参数
num_dict: dictionary
all values are numeric
min_cutoff: float
与num_dict
值进行比较。返回其值> = min_cutoff的所有键。
我的字典是{'Denver': 200, 'Houston': 100, 'NOLA':50}
def keys_get_cutoff(num_dict, min_cutoff):
for k, v in num_dict.items():
if v >= min_cutoff:
print(keys_get_cutoff(num_dict, min_cutoff))
答案 0 :(得分:0)
def keys_get_cutoff(dict, min_value):
return [key for key in dict.keys() if dict[key] >= min_value]
答案 1 :(得分:0)
使用列表理解。 see more details about list comprehension
例如。
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']