from typing import MutableSequence
from typing import MutableMapping


def to_plain_python(obj):
    """Convert nested structure mixing dict/list objects with dict/lits (such as the output)
    of loading via ``ruamel.yaml`` to using builtin dict/list only.
    """
    if isinstance(obj, (list, MutableSequence)):
        return [to_plain_python(elem) for elem in obj]
    elif isinstance(obj, (dict, MutableMapping)):
        return {key: to_plain_python(elem) for key, elem in obj.items()}
    else:
        return obj