Search
 
SCRIPT & CODE EXAMPLE
 

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()))
Comment

PREVIOUS NEXT
Code Example
Python :: print command in python 
Python :: dht22 micropython library 
Python :: sanic ip whitelist 
Python :: django startapp in a folder,,while inside that folder 
Python :: django admin difference between superuser and staff 
Python :: pandas to_csv overwrite check 
Python :: appropriate graph for dataset visualization 
Python :: reemplazar un caracter de un string 
Python :: add column to wandb.Table 
Python :: scaling, cross validation and fitting a model through a pipline 
Python :: how to make a value 0 if its negatice 
Python :: 2D list from dataframe column 
Python :: how to access github folder in python code using github https link 
Python :: Pandas: Ternary conditional operator for setting a value in a DataFrame 
Python :: python tkinter button multiple commands 
Python :: odoo.py odoo 14 
Python :: odoo 12 compute documentation 
Python :: run php websevrer with python 
Python :: qlabel click python 
Python :: is python3 enough for react native 
Python :: why am i not able to import wtf flask 
Python :: how to use the dot lower function 
Python :: QAction pressed pyqt5 
Python :: python how to initialize wikipediaapi 
Python :: how to upload to PyPi with same name 
Python :: reference other libraries in library 
Python :: assert vs validate in python 
Python :: Programmatically determining programming languages based on file extensions in python 
Python :: gfrequency listing in pandas 
Python :: how to check if a function false python 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =