Practice Memory Diagram


Snippet

    def increment_values(dct):
        for key in dct:
            value = dct[key]

            if type(value) == int:
                dct[key] = value + 1

            elif type(value) == dict:
                increment_values(value)

    dct1 = {'a': 1, 'b': 2, 'c': 3}
    increment_values(dct1)
    print(dct1)

    dct2 = {'x': {'a': 5}, 'y': {'a': 1, 'b': 2}, 'z': {'b': 3}}
    increment_values(dct2)
    print(dct2)

Solution

Image Description Here

Image Description

(Coming Soon)

Contributor(s): Viktorya Hunanyan