Comprehension to find the min in a dict

前端 未结 6 1188
鱼传尺愫
鱼传尺愫 2021-01-25 05:19

I am curious about a thing:

I have a dict, for example with a car as key and a value regarding its speed. Now, I want to find the key with the lowest value.



        
6条回答
  •  无人共我
    2021-01-25 06:11

    This would do you can compare the key's value to the min of the values

    worst = [i for i in car_dict if car_dict[i] == min(car_dict.values())]
    

提交回复
热议问题