Permutations of a list split into two strings
<p>Using the following list as an example :</p>

<pre><code>a = ["cat", "dog", "mouse", "rat", "horse"]
</code></pre>

<p>I can get all permutations using <code>itertools.permutations</code></p>

<pre><code>print (list(itertools.permutations(a, 2)))

[('cat', 'dog'), ('cat', 'mouse'), ('cat', 'rat'), ('cat', 'horse'), ('dog', 'cat'), ('dog', 'mouse'), ('dog', 'rat'), ('dog', 'horse'), ('mouse', 'cat'), ('mouse', 'dog'), ('mouse', 'rat'), ('mouse', 'horse'), ('rat', 'cat'), ('rat', 'dog'), ('rat', 'mouse'), ('rat', 'horse'), ('horse', 'cat'), ('horse', 'dog'), ('horse', 'mouse'), ('horse', 'rat')]
</code></pre>

<p>But what if I need to get this output in the following format which is a list of lists containing all items split in two strings as follows:</p>

<pre><code>[["cat", "dog mouse rat horse"], ["cat dog", "mouse rat horse"], ["cat dog mouse", "rat horse"], ["cat dog mouse rat", "horse"]]
</code></pre>

<p>Slicing input list and joining string can do a job for you.</p>

<pre><code>seq = ["cat", "dog", "mouse", "rat", "horse"]
seq2 = [[' '.join(seq[:i+1]), ' '.join(seq[i+1:])] for i in range(len(seq)-1)]
# [['cat', 'dog mouse rat horse'], ['cat dog', 'mouse rat horse'], ['cat dog mouse', 'rat horse'], ['cat dog mouse rat', 'horse']]
</code></pre>

python