-
Notifications
You must be signed in to change notification settings - Fork 244
Merge Catalogs
Sar Champagne Bielert edited this page Apr 8, 2024
·
4 revisions
Unit 2 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
- Does the order I add the dicts matter?
- Yes, because if there is a duplicate element, the second catalog gets priority.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Loop through each item in catalog 2, and add/overwrite the entry in catalog 1.
1) For each product and price in catalog 2:
a) Set that product -> that price in catalog 1
2) Return the updated catalog 1
def merge_catalogs(catalog1, catalog2):
for product, price in catalog2.items():
catalog1[product] = price
return catalog1