I have a start end, and a step, I would like to create a list like this (start= 0, end = 300, step = 100):
[[1, 100], [101, 200], [201, 300]]
The start, end, and step will vary, so I have to dynamically create the list.
>>> start = 0
>>> end = 300
>>> step = 100
>>> [[1 + x, step + x] for x in range(start, end, step)]
[[1, 100], [101, 200], [201, 300]]
You just need a simple while loop: -
start = 0
end = 300
step = 100
my_list = []
while start < end: # Loop until you reach the end
my_list.append([start + 1, start + step])
start += step # Increment start by step value to consider next group
print my_list
OUTPUT : -
[[1, 100], [101, 200], [201, 300]]
The same thing can be achieved by range or xrange function, in a list comprehension.
[1,100]?