Answers for "python get key value"

5

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))
Posted by: Guest on June-12-2020
14

python get dictionary keys

# To get all the keys of a dictionary use 'keys()'
newdict = {1:0, 2:0, 3:0}
newdict.keys()
# Output:
# dict_keys([1, 2, 3])
Posted by: Guest on February-21-2020
0

how to get the value of key in python

print(dict.get("key"))
Posted by: Guest on May-17-2020
0

python get dictionary keys

d = {2:"hello"}
d.values()
Posted by: Guest on September-16-2020
0

get a value using a dictionary key in python

print(d.get('key5', 'NO KEY'))
# NO KEY

print(d.get('key5', 100))
# 100
Posted by: Guest on November-10-2021

Code answers related to "python get key value"

Python Answers by Framework

Browse Popular Code Answers by Language