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><code>++</code> and <code>--</code> have been deliberately excluded from Python, because using them in expressions tends to lead to confusing code and off-by-one errors.</p>

<p>You should use <a href="https://docs.python.org/3/library/functions.html#enumerate" rel="nofollow"><code>enumerate</code></a> instead:</p>

<pre><code>def list_of_pairs(seq, start):
    return [[elem, i] for i, elem in enumerate(seq, start)]
</code></pre>

python list