在python中。要查找排列,我们使用itertools.permutation()...但是由于我的字符串太长,我的笔记本电脑一次又一次崩溃,那么如何分配工作?对于EG-
A=the first eighty permutations
B=the second lot of the permutations.
C=the third eighty lot..
我的代码是
Import itertools
Print(itertools.permuatations(a,b,c,d,e,f,g,h,I,j,k,l,m,n,o,p,q, r,s, t,u,v,w,x,y,z)
[注意:我将字母作为字符串输入,在程序中我无法在手机上编写太多内容...所以请...如果未定义,则必须添加引号。。谢谢!
itertools.permutations
已经返回了一个生成器对象,该对象可以节省内存,因此我们只需要一次从其中提取N个块的方法,例如:
perms = itertools.permutations('ABCDE', 4) # our generator object
chunksize = 80 # how many permutations to work with at a time
while True:
current = list(itertools.islice(perms, chunk))
# do whatever you want with current here
if not current: # generator has been depleted, end the loop
break