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>This could be solution that is flexible and work for any range. </p>

<pre><code>def custom_range(first, second, range_limit):
    start , end = range_limit
    step = first + second
    a = range(start, end, step)
    b = range(first, end, step)
    from itertools import izip_longest
    print [j for i in izip_longest(a,b) for j in i if j!=None]

custom_range(4,2,(0,19))
custom_range(6,5,(0,34))
</code></pre>

<p>Output:</p>

<pre><code>[0, 4, 6, 10, 12, 16, 18]
[0, 6, 11, 17, 22, 28, 33]
</code></pre>

python increment