Get key with maximum value in Dictionary Last Updated : 06 May, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a dictionary, our task is to find the key having the maximum value. For Example: We are given a dictionary d = {'Audi':100, 'BMW':1292, 'Jaguar': 210000, 'Hyundai' : 88} then the output will be Jaguar as it is the key with maximum value in dictionary.Using max() with a Key FunctionIn this method we will use the built-in max() function to identify the key with the highest value in the dictionary and by specifying key=d.get we can ensure that the comparison is based on the dictionary values rather than the keys. Python d = {'Audi':100, 'BMW':1292, 'Jaguar': 210000, 'Hyundai' : 88} res = max(d, key=d.get) print(res) OutputJaguar Explanation: max() function is used to find the maximum element where key=d.get ensures the comparison is made based on the values (not keys).Using sorted()We use the sorted() function to sort the dictionary by its values in descending order and then pick the first key from the sorted list which will correspond to the maximum value. Python d = {'Audi':100, 'BMW':1292, 'Jaguar': 210000, 'Hyundai' : 88} res = sorted(d, key=d.get, reverse=True)[0] print(res) OutputJaguar Explanation: sorted() function sorts the dictionary keys based on their values using key=d.get and setting reverse=True to sort in descending order and the first key in the sorted list is the one with the highest value.Using a LoopWe iterate through each key-value pair in the dictionary comparing the value of each pair with the current maximum value. The key with the highest value is stored and returned at the end of the loop. Python d = {'Audi':100, 'BMW':1292, 'Jaguar': 210000, 'Hyundai' : 88} mk = None # max_key mv = float('-inf') # max_value for k, v in d.items(): if v > mv: mv = v mk = k print(mk) OutputJaguar Explanation:We initialize max_value(mv) as negative infinity and max_key(mk) as None.In the loop, we compare each dictionary value with max_value and update both max_value and max_key when a larger value is found.Using max() with a Lambda FunctionWe use the max() function with a lambda function to access the dictionary values, this allows us to find the key associated with the maximum value. Python d = {'Audi':100, 'BMW':1292, 'Jaguar': 210000, 'Hyundai' : 88} res = max(d, key=lambda k: d[k]) print(res) OutputJaguar Explanation:lambda function returns the value corresponding to each key (d[k]).max() function then compares the values returning the key with the maximum value.Related Articles:Python – max() functionPython sorted() FunctionLoops in Pythonlambda function Python program to Get Key with maximum value in Dictionary Comment More infoAdvertise with us Next Article Python - Extract Maximum Keys' value dictionaries E everythingispossible Follow Improve Article Tags : Python Python Programs python-dict Python dictionary-programs Practice Tags : pythonpython-dict Similar Reads Python - Maximum record value key in dictionary Sometimes, while working with dictionary records, we can have a problem in which we need to find the key with maximum value of a particular key of nested records in list. This can have applications in domains such as web development and Machine Learning. Lets discuss certain ways in which this task 6 min read Python - Maximum of filtered Keys in dictionary Sometimes while working with Python dictionaries, we might have a problem in which we require to just maximum the selective key values from the dictionary. This problem can occur in web development domain. Letâs discuss certain ways in which this problem can be solved. Method #1: Using list comprehe 6 min read Python - Key with Maximum element at Kth index in Dictionary Value List Given a dictionary with values as lists, the task is to write a Python program to get the key with the maximum element at the Kth index by comparing the elements of each list. Input : test_dict = {'Gfg' : [4, 6, 8, 2], 'is' : [1, 4, 5, 9], 'best' :[2, 3, 4, 10], 'for' :[4, 5, 2, 1], 'geeks' :[2, 10, 8 min read Python - Extract Maximum Keys' value dictionaries Given a dictionary, extract all the dictionary which contains a any key which has maximum values among other keys in dictionary list. Input : [{"Gfg" : 3, "is" : 7, "Best" : 8}, {"Gfg" : 9, "is" : 2, "Best" : 9}, {"Gfg" : 5, "is" : 4, "Best" : 10}, {"Gfg" : 3, "is" : 6, "Best" : 14}] Output : [{"Gfg 6 min read Get Maximum of Each Key Dictionary List - Python We are given a list of dictionaries and our task is to find the maximum value for each key across all dictionaries. If a key appears in multiple dictionaries we take the highest value among them. For example: a = [{'a': 3, 'b': 8}, {'a': 10, 'b': 2, 'c': 5}, {'c': 12, 'a': 7}] then the output will b 2 min read Python - Maximum Value in Nested Dictionary Sometimes, while working with python dictionary, we can have problem in which each key in itself is a record with several keys and we desire to substitute the value as maximum value of keys of dictionary. This kind of problem can have application in many domains that involves data. Lets discuss cert 4 min read Like