get key of dict python code example
Example 1: how to get key of a particular value in dictionary python using index
mydict = {'george': 16, 'amber': 19}
print(list(mydict.keys())[list(mydict.values()).index(16)]) # Prints george
Example 2: how to get the value of key in python
print(dict.get("key"))
Example 3: 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)
Example 4: find key by value python
print(list(d.keys())[list(d.values()).index(990)])