擅长:python、mysql、java
<p>可以对生成器使用递归:</p>
<pre><code>def get_paths(d, _c = []):
val, _l, _r = d
if _l is None and _r is None:
yield [*_c, val]
if _l is not None:
yield from get_paths(_l, _c = _c+[val])
if _r is not None:
yield from get_paths(_r, _c = _c+[val])
print(list(get_paths((1,(2,(4,(7,None,None),None),(5, None, None)),(3,None,(6, None,None))))))
</code></pre>
<p>输出:</p>
<pre><code>[[1, 2, 4, 7], [1, 2, 5], [1, 3, 6]]
</code></pre>