This might be silly. I cannot figure it out right now.
There is a total number (x)
Which needs to be divided equally with (y)
If x is 10,000 and y is 10,
That would mean 10,000 is to be spit between 10.
How to find the starting point as
1 starts at 1 and ends 1,000
2 starts at 1,001 & ends 2,000
3 ..
4 ..
5 ..
This is really just some simple maths:
Gives us:
Here we use the
range()builtin and a list comprehension.This works by using the
range()builtin to construct a generator from1to belowx, taking steps ofxdivided (integer division, so we don’t get a floating point number) byy.We then use a list comprehension to take these values (
1, 1001, 2001, ..., 9001) and then put them into tuple pairs, adding(x//y-1)(in this case999) to the value to get the ending boundary.Naturally, if you want to use this in a loop, for example, you would be better off with a generator expression so that it’s evaluated lazily, over a list comprehension. E.g: