我使用的代码是:
#!/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))
从here和here获取一些信息,但无法解决我的问题。你知道吗
我只想把这些单词排列成所有可能的组合,不可重复的短语,长度为60个字符。你知道吗
这将打印所有排列,当组合成一个字符串时,长度为60:
但无论如何,这样做没有多大意义,因为序列的排列总是包含该序列的所有元素,所以组合的字符串总是具有相同的长度,只有内部单词的顺序会改变。你知道吗
所以你可以先做检查,然后再循环排列。你知道吗
或者可以生成允许不同长度的组合。你知道吗
相关问题 更多 >
编程相关推荐