Python converts two lists into dictionaries, takes the most value of the dictionary value (value), and obtains the corresponding key (key)

method 1

list1 = [‘1’,‘2’,‘3’]
list2 = [‘a’,‘b’,‘c’]
dict1 = dict(map(lambda x,y:[x,y],list1,list2))

result

print(dict1)
[Out] {‘1’: ‘a’, ‘2’: ‘b’, ‘3’: ‘c’}

method 2

dict(zip(list1,list2))
[Out] {‘1’: ‘a’, ‘2’: ‘b’, ‘3’: ‘c’}

Find the smallest value

minValue = min(dict1.values())

Through traversal, find keys by value

for k,v in dict1.items():
    if v == minValue:
        print(k)

Guess you like

Origin blog.csdn.net/qq_35762060/article/details/110500372