Question: Problem B . ( 8 points ) Phonebook Lookup Write a function phonebook ( office _ name, office _ phone ) that takes in two
Problem B points Phonebook Lookup
Write a function phonebookofficename, officephone that takes in two dictionaries:
In officename, 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 officephone, 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 officename dictionary and that office has a phone the office appears as a key in the officephone 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 officename first, and then check whether each key that is each office appears in the officephone 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 namemain:
print
printphonebook:'Victoria', :'Volkan', C:'Mats'
C:::
# Victoria: 'Mats':
printphonebook:'Scot', :'Anar', A:'Rina'
A::
::
# Scot: 'Anar': 'Rina':
printphonebook:'Dania', N:'Faith'
L:D:
#
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
