I know that it is possible to create a list of a range of numbers:
list(range(0,20,1))
output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
but what I want to do is to increment the step on each iteration:
list(range(0,20,1+incremental value)
p.e. when incremental = +1
expected output: [0, 1, 3, 6, 10, 15]
Is this possible in python?
incremental_value
is one, the result would be[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
. Or do you want to increment the step by one on each iteration? – Allysonwhile
loop, or a generator (generators can store state ofstep
, whereas iterators can't) as per the top-two answers here. – Lagrange