Question: Problem B . ( 8 points ) Phonebook Lookup Write a function phonebook ( office _ name, office _ phone ) that takes in two

Problem B.(8 points) Phonebook Lookup
Write a function phonebook(office_name, office_phone) that takes in two dictionaries:
In office_name, the keys are strings representing the room numbers for offices, and the values are strings representing the name of the professor who works in that office.
In office_phone, the keys are strings representing room numbers for offices, and the values are strings representing the phone numbers for each office.
Return a new dictionary where the keys are the names of each professor, and the values are the phone numbers for their offices.
You only need to include professors that both have an office (their name appears as a value in the office_name dictionary) and that office has a phone (the office appears as a key in the office_phone dictionary. You may assume that no professor has more than one office.
Hints:
You can use the in keyword to determine whether a given key is present in a dictionary.
Loop through office_name first, and then check whether each key (that is each office) appears in the office_phone dictionary as well.
If so, then get the values (the professor and the phone number for that office) and add them to your output dictionary.
Examples:
if __name__=='__main__':
print()
print(phonebook({'85':'Victoria', '213':'Volkan', '192C':'Mats'},
{'192C':'625-2068','85':'625-3543','211':'626-1284'}))
# {'Victoria': '625-3543', 'Mats': '625-2068'}
print(phonebook({'354':'Scot', '355':'Anar', '112A':'Rina'},
{'112A':'625-9835','512':'626-9137',
'355':'624-5224','354':'625-5507'}))
# {'Scot': '625-5507', 'Anar': '624-5224', 'Rina': '625-9835'}
print(phonebook({'4-192':'Dania', '4-192N':'Faith'},
{'4-192L':'624-8311','4-192D':'626-8020'}))
# {}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!