Python: simple way to increment by alternating values?
<p>I am building a list of integers that should increment by 2 alternating values. </p>

<p>For example, starting at 0 and alternating between 4 and 2 up to 20 would make:</p>

<pre><code>[0,4,6,10,12,16,18]
</code></pre>

<p>range and xrange only accept a single integer for the increment value. What's the simplest way to do this? </p>

<p>You can use a list comprehension and the modulus operator to do clever things like that. For example:</p>

<pre><code>&gt;&gt;&gt; [3*i + i%2 for i in range(10)]
[0, 4, 6, 10, 12, 16, 18, 22, 24, 28]
</code></pre>

python increment