I have the following problem and I cannot figure out what to do. Can someone help???
"You are throwing a party and want to pair up people with similar interests. You have already collected data about each of your guest’s favorite interest in a dictionary like so:
interests = { 'Sophia' : 'Computer', 'Anders' : 'Dancing', 'Mette' : 'Dancing', 'Hikari' : 'Computer', 'Riko' : 'Rowing', 'Troels' : 'Rowing', 'Sarah' : 'Rowing' }
To be able to quickly suggest topics at the party, you need to convert this dictionary into a different layout.
Your task is to write a function transform_dictionary that takes as argument a dictionary such as the one above and returns a dictionary in which each key is an interest and the value is a list of all the people that share this interest. For example, for the list above, the dictionary that is returned is (disregarding a particular order of elements)
I need to print:
{'Computer': ['Sophia', 'Hikari'], 'Dancing': ['Anders', 'Mette'], 'Rowing': ['Riko', 'Troels', 'Sarah']}
This is what I have so far:
interests = {
'Sophia' : 'Computer',
'Anders' : 'Dancing',
'Mette' : 'Dancing',
'Hikari' : 'Computer',
'Riko' : 'Rowing',
'Troels' : 'Rowing',
'Sarah' : 'Rowing'
}
# comvert dictionary into a different layout.
def transform_dictionary(interests):
new_dict = {}
key_list = []
for k, v in new_dict:
if value in new_dict:
new_dict[value] = k
return {}
print(transform_dictionary(interests))