Advertisement
plarmi

Get key by value in Python's dict

Sep 26th, 2023
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.21 KB | None | 0 0
  1. dictionary1 = {'a': 300, 'b': 400}
  2.  
  3. def get_key_by_value(dictionary, value):
  4.     for key, val in dictionary.items():
  5.         if val == value:
  6.             return key
  7.  
  8. print(get_key_by_value(dictionary1, 400))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement