擅长:python、mysql、java
<p>我想你可以在@wjandrea的评论里做点什么:</p>
<pre><code>from itertools import combinations, permutations
lst = [1,2,3,4,5,6,7,8,9]
strings = ['foo', 'bar', 'foobar']
for positions in combinations(range(len(lst) + len(strings)), len(strings)):
for permutation in permutations(strings, len(strings)):
cop = lst[:]
for string, pos in zip(permutation, positions):
cop.insert(pos, string)
print(cop)
</code></pre>
<p><strong>输出</strong>(小样本)</p>
<pre><code>['foo', 'foobar', 1, 2, 3, 'bar', 4, 5, 6, 7, 8, 9]
['bar', 'foo', 1, 2, 3, 'foobar', 4, 5, 6, 7, 8, 9]
['bar', 'foobar', 1, 2, 3, 'foo', 4, 5, 6, 7, 8, 9]
['foobar', 'foo', 1, 2, 3, 'bar', 4, 5, 6, 7, 8, 9]
['foobar', 'bar', 1, 2, 3, 'foo', 4, 5, 6, 7, 8, 9]
['foo', 'bar', 1, 2, 3, 4, 'foobar', 5, 6, 7, 8, 9]
['foo', 'foobar', 1, 2, 3, 4, 'bar', 5, 6, 7, 8, 9]
</code></pre>
<p>请注意,此解决方案假设您可以对字符串重新排序。你知道吗</p>