0

这是我的代码:

import more_itertools as mit
import itertools as it

alfa1 = "abcdefghijk"
alfa2 = "1234567890"
listado = open("listado.txt", "w")
mayus= list()
minus=list()
aux = list()
juntos = list()
# All possible number of uppers
i=2
  # All possible permutations of 'n' uppers
for upper_str in it.permutations(alfa2, i):
    # All possible permutations of 14-n lowers
    print ("".join(upper_str))
    mayus.append("".join(upper_str))
for lower_str in it.combinations_with_replacement(alfa1, 5-1):
        minus.append("".join(lower_str))
for r in range(len(mayus)):
    juntos.append("".join(mayus[r])+"".join(minus[r])+"\n")
    listado.write(juntos[r])
listado.close()

我做到了,这样我就可以在输出中控制每个数字的数量,效果很好,现在我想允许“aabbcc ..”。允许重复 2 个字母,我尝试的是在基本列表上重复该字母两次,但我的结果与我没有这样做的结果相同(例如 alfa="abc" 所以允许我制作两个字母它“aabbcc”)。

我还能如何将重复的字母限制为两个并进行长度为 5 的排列?

4

0 回答 0