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 can achieve the same with <a href="https://docs.python.org/2/library/itertools.html#itertools.count" rel="nofollow"><code>itertools.count</code></a>, calling <code>next</code> on the <code>count</code> object for each element of the sequence:</p>

<pre><code>from itertools import count

c = count(start)
lst = [[x, next(c)] for x in seq]
</code></pre>

<blockquote>
  <p>construct the list using square brackets</p>
</blockquote>

<p>That's a <em>list comprehension</em>. It's pretty standard and most certainly Pythonic to use list comprehensions for creating lists.</p>

python list