Python One-Line Tree using defaultdict. How to reduce the number of arguments required?

独自空忆成欢 提交于 2019-12-07 13:44:31

You can simply define a funcion, say insert to create the node by providing a list and tree as argument.

def insert(tree, List):
    for node in List:
        tree = tree[node]

users = tree()
insert(users, ['harold', 'username', 'hrldcpr'])

would create a structure as {'harold' : {'username' : {'hrldcp' : {} } } }

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!