Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

get key name from dictionary python code example

Example 1: how to get the key for a value in a dictionary in python

# function to return key for any value 
def get_key(val): 
    for key, value in my_dict.items(): 
         if val == value: 
             return key 
  
    return "key doesn't exist"
  
# Driver Code 
  
my_dict ={"java":100, "python":112, "c":11} 
  
print(get_key(100)) 
print(get_key(11))

Example 2: find key by value python

print(list(d.keys())[list(d.values()).index(990)])

Tags:

Typescript Example

Related

testing internet connection code example [ng] An unhandled exception occurred: Cannot find module '@angular-devkit/build-angular/package.json' [ng] Require stack: code example ghow to delete a commit code example delete object in javascript code example 1/n factorial code example install dart from flutter sdk code example repeat video html' code example how work cascade delte code example p5.js createcanvas code example html js programmatically event listener parameter code example sort array by date php code example jjava script check string equality case insensitive code example

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy