在使用itertools permutations函数后列表中存在一些问题。将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']
调用排列'combinations'是混乱的。 – DSM 2013-04-28 16:58:52