logo CodeStepByStep logo


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()
    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?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.