This question is very similar to Python: Slicing a list into n nearly-equal-length partitions.
However, I don't want to actually slice a list. All I want are the start and stop index values of each chunk as if I was slicing the list.
So what I'd like is a function that takes input:
def partitionIndexes( totalsize, numberofpartitions):
and returns a list of tuples representing the start and end index of each partition. Each tuple should span roughly the same number of indices (within 1).
Example:
>>>partitionIndexes( 105, 10 )
[(0, 10)
(11, 21)
(22, 32)
(33, 43)
(44, 54)
(55, 64)
(65, 74)
(75, 84)
(85, 94)
(95, 104)]
Notice how the first five partitions span 11 indices and the last five partitions span 10 indices.
If possible, I'd like to avoid having to generate an intermediate list of all indexes.