Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

looping through the dict. and return the key with the highest value

dict1 = {"a": 18, "x": 2, "y": 3, "z": 10}

key_with_the_highest_value = list(dict1.keys())
for keys, values in (dict1.copy()).items():
    for values2 in (dict1.copy()).values():
        if values >= values2:
            continue
        if values < values2:
            key_with_the_highest_value.remove(keys)
            break

print(f"The key with the highest value is: {key_with_the_highest_value}")

# SIMPLIFIED ANSWER WITHOUT LOOPING
# print(max(dict1.keys()))
 
PREVIOUS NEXT
Tagged: #looping #return #key #highest
ADD COMMENT
Topic
Name
4+4 =