且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Python中从列表创建嵌套字典?

更新时间:2023-02-17 12:55:02

最简单的方法是从内而外地构建字典:

This easiest way is to build the dictionary starting from the inside out:

tree_dict = {}
for key in reversed(tree_list):
    tree_dict = {key: tree_dict}