内置用于创建n长度字符集的排列?

Loc*_*ane 3 python permutation python-itertools

我知道itertools.permutations(),但我要问的是略有不同.

给出角色列表:

["*", "/", "+", "-"]
Run Code Online (Sandbox Code Playgroud)

是否有内置的将创建N长度的所有排列的给定字符的列表?所以,例如,如果我想要长度7:

["*", "*", "*", "*", "*", "*", "*"]
["*", "*", "*", "*", "*", "*", "/"]
["*", "*", "*", "*", "*", "*", "+"]
  ... <after much processing> ...
["-", "-", "-", "-", "-", "-", "/"]
["-", "-", "-", "-", "-", "-", "+"]
["-", "-", "-", "-", "-", "-", "-"]
Run Code Online (Sandbox Code Playgroud)

就目前而言,我编写了自己的递归程序来生成它们,但我确信有一些神奇的线路调用我不知道了.

Ara*_*Fey 5

您正在寻找的是7个["*", "/", "+", "-"]列表的笛卡尔积.itertools.product需要一个repeat论据正是为此目的:

for row in itertools.product(["*", "/", "+", "-"], repeat=7):
    print(row)
Run Code Online (Sandbox Code Playgroud)