get key from a particular value in dictionary python code example
Example 1: how to retrieve dictionary values in python by index
a_dictionary = {"a": 1, "b": 2, "c":3}
keys_list = list(a_dictionary)
key = keys_list[0]
print(key)
Example 2: 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)])
Example 3: how to get element from dictionary python
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
dict['Age'] = 8;
dict['School'] = "DPS School";
print "dict['Age']: ", dict['Age']
print "dict['School']: ", dict['School']
Example 4: get key from a value
person = {'name': 'Phill', 'age': 22}
print('Name: ', person.get('Phill'))
print('Age: ', person.get('age'))
print('Salary: ', person.get('salary'))
print('Salary: ', person.get('salary', 0.0))