使用itertools的permutations函数后,遇到了列表问题。
输出结果如下:
from itertools import permutations
def longestWord(letters):
combinations = list(permutations(letters))
for s in combinations:
''.join(s)
print(combinations)
longestWord("aah")
输出结果如下:
[('a', 'a', 'h'), ('a', 'h', 'a'), ('a', 'a', 'h'), ('a', 'h', 'a'),
('h', 'a', 'a'), ('h', 'a', 'a')]
我希望这是一个简单的列表,但它似乎变成了元组的列表。有人能帮我格式化它,使其输出如下:
['aah', 'aha', 'aah', 'aha', 'haa', 'haa']