My code returns an empty list?

I think this code should work… But it returns an empty list. I swear we used the same format in the scrabble exercise.

def values_that_are_keys(my_dictionary): 
  value_key_list = []
  for key, value in my_dictionary.items():
    if key == value:
      value_key_list.append(key)
  return value_key_list
# Uncomment these function calls to test your  function:
print(values_that_are_keys({1:100, 2:1, 3:4, 4:10}))

Your function only returns values which are the same as their own keys, i.e., {100: 100}.

But in the example you show, there is no key:value combination like that. The values 1 and 4, however, are also found as keys elsewhere in the dictionary.

3 Likes