Unit 2 Session 2 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Loop through each key in d1, check if it's in d2. If so, check if their values match. If they do, add to a list of matches.
1) Create an empty dict for matches
2) Loop through each key in d1
a) If the key is also in d2 AND both values match
i) Add to matches dict
3) Return matches dict
def dict_intersection(d1, d2):
result = {}
for key in d1:
if key in d2 and d1[key] == d2[key]:
result[key] = d1[key]
return result