【发布时间】:2015-08-18 19:44:06
【问题描述】:
我正在使用此代码:
#!/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 循环中的排列。
-
我正在尝试仅打印长度为 60 char len 的短语。
标签: python python-3.4 itertools