Skip to content

Instantly share code, notes, and snippets.

@upsuper
upsuper / tree.md
Created Apr 28, 2012 — forked from hrldcpr/tree.md
一行 Python 实现树
View tree.md

一行 Python 实现树

使用 Python 内置的 defaultdict,我们可以很容易的定义一个树形数据结构:

def tree(): return defaultdict(tree)

就是这样!