-
Notifications
You must be signed in to change notification settings - Fork 254
Print Pair
Sar Champagne Bielert edited this page Apr 8, 2024
·
3 revisions
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: Print a requested dictionary entry, or an error if not found.
1) Check if the target is in the dictionary keys
2) If so:
a) print the target as the key
b) use the key to get the value and print the value
3) If not, print an error message
def print_pair(dictionary, target):
if target in dictionary:
print("Key: " + target)
print("Value: " + dictionary[target])
else:
print("That pair does not exist!")