def walk(obj, parent_first=True):
    if parent_first:
        yield (), obj
if isinstance(obj, dict):
    children = list(obj.items())
elif isinstance(obj, (list, tuple)):
    children = enumerate(obj)
else:
    children = []
for key, value in children:
    for child_path, child in walk(value, parent_first):
        yield (key,) + child_path, child
if not parent_first:
    yield (), obj
Извлечение всего пути из многоуровневого словаря