solutions

Write a function that inverts a dictionary's keys and values so that all values are now keys, and that all keys are now values.

a_dict = {1: 'a', 2: 'b', 3:'c'}

invert_dict(a_dict) # {'a': 1, 'b': 2, 'c': 3}

Test Cases

test invert empty dict - Run Test

def test_invert_empty_dict():
    assert invert_dict({}) == {}

test invert one element dict - Run Test

def test_invert_one_element_dict():
    assert invert_dict({1: 'a'}) == {'a': 1}

test invert many elements dict - Run Test

def test_invert_many_elements_dict():
    assert invert_dict({
        1: 'a', 2: 'b',
        3: 'c', 4: 'd',
        5: 'e'
    }) == {
        'a': 1, 'b': 2,
        'c': 3, 'd': 4,
        'e': 5
    }