I have the dictionary as shown below and I want to pick the key whose value is the maximum in dictionary
dictionary = {'george': 16, 'amber': 19 ,'leper':23}
Expected_Output: leper
I have the dictionary as shown below and I want to pick the key whose value is the maximum in dictionary
dictionary = {'george': 16, 'amber': 19 ,'leper':23}
Expected_Output: leper
This may not be the best method to get the answer when it comes to time complexity
dictionary = {'george': 16, 'amber': 19, 'leper': 23}
# Creating the list of values
values = [i for i in dictionary.values()]
# Creating the list of keys
keys = [i for i in dictionary.keys()]
# Declaring the g [greater value]
g = int
# iterating through the list to find the maximum value
for i in range(len(values)):
try:
temp_i = values[i+1]
except IndexError:
temp_i = values[i]
for i in values:
if temp_i > i:
g = temp_i
else:
g = i
pos = values.index(g)
print(keys[pos])