Implement function lookup() that implements a phone book lookup application. You
ID: 3547692 • Letter: I
Question
Implement function lookup() that implements a phone book lookup application. Your functiontakes, as input, a dictionary representing a phone book. Int the dictionary, tuples containing first and last names of individual (the keys) are mapped to strings containing phone numbers(the values)
Your function should provide a simple interface through which a user can enter the first and last names of an individual and obtain the phone number asiigned to that individual.
You must take into consideration that more than one person can have the same first and last name. A modified dictionary that maps a tuple to a list of phone numbers could be used to implement a more realistic phone book.
Explanation / Answer
You just need to do this with the dictionary
for key, val in telephone_directory.items():
if search_key in key:
print("Found a match! {}".format(val))
break
else:
print("Nothing found")
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.