1
2# function to return key for any value
3def get_key(val):
4 for key, value in my_dict.items():
5 if val == value:
6 return key
7
8 return "key doesn't exist"
9
10# Driver Code
11
12my_dict ={"java":100, "python":112, "c":11}
13
14print(get_key(100))
15print(get_key(11))
16
1mydict = {'george': 16, 'amber': 19}
2print(list(mydict.keys())[list(mydict.values()).index(16)]) # Prints george
1dict = {'color': 'blue', 'shape': 'square', 'perimeter':20}
2dict.get('shape') #returns square
3
4#You can also set a return value in case key doesn't exist (default is None)
5dict.get('volume', 'The key was not found') #returns 'The key was not found'
1k = {1:10,2:20,3:30,4:40}
2#idea : print([5,6,7,8][[12,15,47,45].index(15)])
3b = list(k.keys())[list(k.values()).index(20)] #find index of 20 => return 2