logo CodeStepByStep logo

dict_mystery3

Language/Type: Python collections dict

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

def mystery(numbers):
    data = {}
    for el in numbers:
        if el in data:
            data[el].append(1)
        else:
            data[el] = []
    return data

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

[1, 2, 34, 3, 4, 1, 2, 4, 2, 14]
[1, 1, 1, 2, 2, 2, 1, 4, 4, 4]
[45, 43, 44, 54, 45, 45, 54, 43]

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.