Source Code:
(back to article)
def get_key(dictionary, value): return next((k for k, v in dictionary.items() if v == value), None) my_dict = {'a': 1, 'b': 2, 'c': 3} print(get_key(my_dict, 2)) # Output: 'b'
Result:
Report an issue