python 全排列
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
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