julia - How to find the key for the min/max value of a Dict?

前端 未结 4 1817
有刺的猬
有刺的猬 2021-02-20 13:57

I want to find the key corresponding to the min or max value of a dictionary in julia. In Python I would to the following:

my_dict = {1:20, 2:10}
min(my_dict, my         


        
4条回答
  •  太阳男子
    2021-02-20 14:33

    Here is another way to find Min with Key and Value

    my_dict = Dict(1 => 20, 2 =>10)
    

    findmin(my_dict) gives the output as below

    (10, 2)
    

    to get only key use

    findmin(my_dict)[2]
    

    to get only value use

    findmin(my_dict)[1]
    

    Hope this helps.

提交回复
热议问题