subject

There's a roster of unique names, and we created a dictionary of first name to list of last names. For example, the roster Alice Chan Bob Smith Fred Agarwal Alice Smith
We've created this dictionary mapping first name to a list of associated last names, but dumped the original roster unfortunately:
{'Alice': ['Chan', 'Smith'], 'Bob': ['Smith'], 'Fred': ['Agarwal']}
But now, we want to search by last name. So given only the above dictionary, return a new dictionary where the key is last name instead of first name.
{'Smith': ['Alice', 'Bob'], 'Chan': ['Alice'], 'Agarwal': ['Fred']}
A Few Notes:
1. The order of the lists of first names is ambiguous, but return it sorted alphabetically from A-Z. That means, 'Smith' should map to ['Alice', 'Bob'], NOT ['Bob', 'Alice'].
2. Even if there's only one person with that last name, make sure it's mapped to a list. That means, 'Agarwal' should map to ['Fred'], NOT 'Fred'.
3. Recall dictionaries (and sets) are unordered, so don't be alarmed if the print statement didn't have the last names in the same order as above. BUT, for each last name, the list of first names associated must be sorted.
4. We've assumed the original roster had unique names, so there aren't any issues with that.
1 def reverse_roster (fn_dict:dict) -> dict:
2 # TODO: Your code here (-10-20 lines of code)
3
4 if __name__ == '__main__':
5 sample = {'Alice': ['Smith', 'Chan'], 'Bob': ['Smith'], 'Fred': ['Agarwal']}
6 print (reverse_roster (sample))
7

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 14:30
The “rule of 72” is used to approximate the time required for prices to double due to inflation. if the inflation rate is r%, then the rule of 72 estimates that prices will double in 72/r years. for instance, at an inflation rate of 6%, prices double in about 72/6 or 12 years. write a program to test the accuracy of this rule. for each interest rate from 1% to 20%, the program should display the rounded value of 72/r and the actual number of years required for prices to double at an r% inflation rate. (assume prices increase at the end of each year.)
Answers: 1
question
Computers and Technology, 22.06.2019 15:00
The three logical operators used to write compound conditions are "and," "or," and "not." a: true b: false
Answers: 2
question
Computers and Technology, 23.06.2019 09:30
Why is an outfitting a workspace with video games in a technology development company considered a strategic use of money
Answers: 1
question
Computers and Technology, 23.06.2019 14:30
Select the correct answer. peter has launched a website that features baby products. however, clients often find they are unable to access the website because the server is down. which feature of cybersecurity should peter focus on for his website? a. data authenticity b. data privacy c. data availability d. data integrity e. data encryption
Answers: 3
You know the right answer?
There's a roster of unique names, and we created a dictionary of first name to list of last names. F...
Questions
question
Mathematics, 22.08.2019 10:30
question
Mathematics, 22.08.2019 10:30
Questions on the website: 13722366