我使用這個代碼textwrap工作:的Python 3.4.3 - 如何使itertools
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import textwrap
import itertools
a = []
a.append('word1')
a.append('word2')
a.append('word3')
a.append('word4')
a.append('word5')
a.append('word6')
a.append('word7')
a.append('word8')
a.append('word9')
a.append('word10')
for permutation in itertools.permutations(a,):
permutation = textwrap.TextWrapper(len=60,break_long_words=False,replace_whitespace=False)
print(' '.join(permutation))
我只是想將這些單詞排列成具有60個字符長度的所有可能的組合不可重複的短語。
我不確定你想用什麼文本包裝。另外,你正在覆蓋for循環中的排列。 – poke
我試圖只打印60個字符長的短語。 –