假设我有单词“apple”,字母集 ['a', 'l', 'e'] 和重复次数 3。据此我想创建以下集合: ['aaapple' 、“aaappllle”、“aaappllleee”、“appllle”、“appllleee”、“appleee”]。
这是我已经尝试过的:
l = ['a', 'l', 'e']
word = "apple"
for i in range(0, len(l)):
print wordWithDuplicatedLetters = "".join(3*c if c == l[i] else c for c in word)
Run Code Online (Sandbox Code Playgroud)
但这并不匹配所有组合,并且 itertools 似乎没有提供我正在寻找的可能性。