You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Understand what the interviewer is asking for by using test cases and questions about the problem.
Will records always be a valid dictionary?
Yes, but it may or may not be empty!
Does the function need to return anything?
No! The problem statement does not specify a return value, just that you modify the dictionary if item is a key in the dictionary records and print "<item> not found!" if item is not a key in the dictionary records.
P-lan
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Check if an item is in the dict, update if so, and otherwise print a customized error message.
1) Check if the key is in the dictionary
2) If so, set the dict at key -> new value
3) Otherwise, print the name of the item and "not found!"
⚠️ Common Mistakes
When printing your error message, be sure to print the actual name of the item provided, not the literal string "<item>".
I-mplement
defupdate_or_warn(records, item, update_value):
ifiteminrecords:
records[item] =update_valueelse:
print(item+" not found!")