itertools模块现成的全排列:
for i in itertools.permutations('abcd',4): print ''.join(i)相关全排列算法:
def perm(l): if(len(l)<=1): return [l] r=[] for i in range(len(l)): s=l[:i]+l[i+1:] p=perm(s) for x in p: r.append(l[i:i+1]+x) return r
本文共 346 字,大约阅读时间需要 1 分钟。
itertools模块现成的全排列:
for i in itertools.permutations('abcd',4): print ''.join(i)相关全排列算法:
def perm(l): if(len(l)<=1): return [l] r=[] for i in range(len(l)): s=l[:i]+l[i+1:] p=perm(s) for x in p: r.append(l[i:i+1]+x) return r
转载于:https://www.cnblogs.com/gccbuaa/p/7343905.html