Answers for "get value of key in dictionary python"

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
0

find value in dictionary python

k = {1:10,2:20,3:30,4:40}
#idea : print([5,6,7,8][[12,15,47,45].index(15)])
b = list(k.keys())[list(k.values()).index(20)] #find index of 20 => return 2
Posted by: Guest on September-10-2021
1

python get keys and values from dict

# using dict.items() to
# get key and value
print ("Dict key-value are : ")
for key, value in test_dict.items():
    print (key, value)
Posted by: Guest on May-13-2021
0

how to get the value of key in python

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

get a value from a dictionary python

#!/usr/bin/python

dict = {'Name': 'Zabra', 'Age': 7}
print "Value : %s" %  dict.get('Age')
print "Value : %s" %  dict.get('Education', "Never")
Posted by: Guest on November-30-2020
2

how to get the value of key in python

print(dict["key"])
Posted by: Guest on May-17-2020

Code answers related to "get value of key in dictionary python"

Python Answers by Framework

Browse Popular Code Answers by Language