Skip to content

Python code snippet – How to get key of a particular value in dictionary using index?

# 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)) 
See also  How to create string in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.