文件结构扁平化

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

def flatten(dictionary):
    stack = [((), dictionary)]
    result = {}
    while stack:
        path, current = stack.pop()
        if not current:
            result["/".join((path ))] = ""
        for k, v in current.items():
            if isinstance(v, dict):
                stack.append((path + (k,), v))
            else:
                result["/".join((path + (k,)))] = v
    return result