我看到这里发布了一些排列的代码,但我实际上没有找到一个好的逐步介绍正在发生什么的教程。如果有人能够解释一下这个代码在每个步骤中实际上是发生了什么,我会非常感激。我似乎无法理解它。我要看的代码是Python中来自http://snippets.dzone.com/posts/show/753 的代码。
def all_perms(str):
if len(str) <=1:
yield str
else:
for perm in all_perms(str[1:]):
for i in range(len(perm)+1):
yield perm[:i] + str[0:1] + perm[i:]
for p in all_perms(['a','b','c']):
print p