Skip to content


Find keys with value

Finds all keys in the provided dictionary that have the given value.

def find_keys(dict, val):
  return list(key for key, value in dict.items() if value == val)

ages = {
  'Peter': 10,
  'Isabel': 11,
  'Anna': 10,
find_keys(ages, 10) # [ 'Peter', 'Anna' ]

More like this

Start typing a keyphrase to see matching snippets.