【发布时间】:2014-09-18 16:37:01
【问题描述】:
def perm_generator(lst):
if len(lst) == 1:
yield lst
else:
for i in range(len(lst)):
for perm in perm_generator(lst[:i] + lst[i+1:]):
yield [lst[i]] + perm
这段代码一直困扰着我,因为我不明白yields 是如何相互连接的。我的理解是yield 的行为类似于return,但它会暂时停止,直到再次调用它。这些yields 是如何工作的?
【问题讨论】:
-
这听起来更像是你不了解它的递归本质。
标签: python generator permutation yield