How to create a list of a range with incremental step?
This is possible, but not with range
:
def range_inc(start, stop, step, inc):
i = start
while i < stop:
yield i
i += step
step += inc
You can do something like this:
def incremental_range(start, stop, step, inc):
value = start
while value < stop:
yield value
value += step
step += inc
list(incremental_range(0, 20, 1, 1))
[0, 1, 3, 6, 10, 15]
Even though this has already been answered, I found that list comprehension made this super easy. I needed the same result as the OP, but in increments of 24, starting at -7 and going to 7.
lc = [n*24 for n in range(-7, 8)]