Solution Review: Keys Matching in Multiple Dictionaries

This lesson will explain how to find keys matching a given value with in as a parameter to the function within multiple dictionaries.

Solution 1: Use a Nested for Loop

  • The outer for loop iterates over the outer dictionary using students.items()
  • The inner for loop iterates over the subdictionary values using subdict.values()
  • If the subitem matches with the address in the parameter, the key is saved in a list. Return the sorted key using sorted(list).

The following python code demonstrates the concept:

Get hands-on with 1200+ tech skills courses.