Is there an equivalent to the C++ pre/postfix operators for use in Python list comprehensions?
<p>I writing a function which populates a list of lists of two elements, where the first element is an element from a different list and the second element is a value which increments.</p>

<pre><code>def list_of_pairs(seq, start):
    """ Returns a list of pairs """
    &gt;&gt;&gt; list_of_pairs([3, 2, 1], 1)
    [ [3, 1], [2, 2], [1, 3] ]
    return [[i, start++] for i in seq]
</code></pre>

<p>Is there an equivalent to the C++ postfix operators which can be used? Thanks!</p>

<p>Bonus question: Is it more Pythonic to use the list constructor, than to construct the list using square brackets? </p>

<p>Edit: Here is my current (less beautiful) workaround -</p>

<pre><code>def list_of_pairs(seq, start):
    """ Returns a list of pairs """
    &gt;&gt;&gt; list_of_pairs([3, 2, 1], 1)
    [ [3, 1], [2, 2], [1, 3] ]
    return [[seq[i], start+i] for i in range(len(seq))]
</code></pre>

<p>You may use <a href="https://docs.python.org/2/library/functions.html#enumerate" rel="nofollow"><code>enumerate()</code></a> to achieve this. Enumerate return the index along with value while iterating over the list of values. And as per your requirement, you need list of <code>list</code> as <code>[val, index + count]</code>. Below is the sample code to achieve that:</p>

<pre><code>&gt;&gt;&gt; seq = [2, 6, 9]
&gt;&gt;&gt; count = 2
&gt;&gt;&gt; [[val, count+i] for i, val in enumerate(seq)]
[[2, 2], [6, 3], [9, 4]]
</code></pre>

python list