get key in dictionary python code example
Example 1: python get dictionary keys
newdict = {1:0, 2:0, 3:0}
newdict.keys()
Example 2: get function in dictionary
print('Salary: ', person.get('salary', 0.0))
Example 3: 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 4: find a key in a dictionary python
fruits = {'apple': 2, 'pear': 5, 'strawberry': 3}
if 'apple' in fruits:
print("Key found!")
else:
print("Key not found!")
Example 5: find key by value python
print(list(d.keys())[list(d.values()).index(990)])