logo CodeStepByStep logo

dict_mystery2

Language/Type: Python collections dict

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

def mystery(dict1, dict2):
    result = {}
    for s in dict1:
        if dict1[s] in dict2:
            result[s] = dict2[dict1[s]]
    return result

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'}

dict1 = {"bar": 1, "baz": 2, "foo": 3, "mumble": 4}, dict2 = {1: "earth", 2: "wind", 3: "air", 4: "fire"}
dict1 = {"five": 105, "four": 104, "one": 101, "six": 106, "three": 103, "two": 102}, dict2 = {99: "uno", 101: "dos", 103: "tres", 105: "cuatro"}
dict1 = {"a": 42, "b": 9, "c": 7, "d": 15, "e": 11, "f": 24, "g": 7}, dict2 = {1: "four", 3: "score", 5: "and", 7: "seven", 9: "years", 11: "ago"}

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.