Can list comprehension have a prefix, suffix?
<p>I need to create a list comprehension and add one extra item at the start and end. Is there a better way than just using a helper function to do it?</p>

<pre><code># convert tuple from permutation into a list with predecessor and successor
def perm_to_list(predecessor, perm, successor):
    result = [predecessor]
    result.extend(list(perm))
    result.append(successor)
    return result

candidates = [perm_to_list(prefix, x, suffix) 
              for x in permutations(something)] 
</code></pre>

<p>As an alternative if speed is <em>critical</em>, thought I'd offer this approach. You can use a <a href="https://docs.python.org/2/library/collections.html#collections.deque" rel="nofollow"><code>deque</code></a> which has native support for appending to either the <em>head</em> or <em>tail</em> of the structure. </p>

<p>It's a double-ended queue data structure, and as such offers <strong><em>O(1)</em></strong> prepending as opposed to <strong><em>O(n)</em></strong> for lists.</p>

<pre><code>from collections import deque
dq = deque(range(1,10))  # Test list passed to deque -&gt; deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
dq.appendleft(0)
dq.append(10)
print dq
deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
</code></pre>

python list-comprehension