logo CodeStepByStep logo

dict_mystery1

Language/Type: Python collections dict

Write the output produced when the following function is passed each of the following dictionaries.

def mystery(dictionary):
    result = {}
    for key in dictionary:
        if key < dictionary[key]:
            result[key] = dictionary[key]
        else:
            result[dictionary[key]] = key
    print(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'}

{'two': 'deux', 'five': 'cinq', 'one': 'un', 'three': 'trois', 'four': 'quatre'}
{'skate': 'board', 'drive': 'car', 'program': 'computer', 'play': 'computer'}
{'siskel': 'ebert', 'girl': 'boy', 'H': 'T', 'ready': 'begin', 'first': 'last', 'begin': 'end'}
{'cotton': 'shirt', 'tree': 'violin', 'seed': 'tree', 'light': 'tree', 'rain': 'cotton'}

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.