logo CodeStepByStep logo

dict_mystery4

Language/Type: Python collections dict

Write the dictionary returned when the following function is passed each of the following dictionaries.

def mystery(dictionary):
    data = {}
    for (key, value) in dictionary.items():
        if value not in data:
            data[value] = set()
        data[value].add(key) 
    return data

Though dictionaries store their contents in unpredictable order, for this problem, write the pairs sorted by ordering of the keys. Write your answer in this format: {key: value, key: value}

{'hello': 4, 'world', 4, 'and': 3}
{'banana': 1, 'peach': 2, 'nectarine': 3, 'kiwi': 1, 'apple': 3}
{'the': 'and', 'and': 'the', 'is': 'the', 'has': 'the', 'and': 'and'}

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.