i looking way split list predefined slices:
a = list(range(1, 1001)) # added list() b = [200, 500, 300]
list a
should sliced len(b)
sublists containing first 200 elements of a, following 500, , last 300. safe assume sum(b) == len(a)
.
is there common function this?
make iterator list (if isn't 1 already) , n
times next
element iterator each n
in b
.
>>> = range(1, 1001) >>> b = [200, 500, 300] >>> a_iter = iter(a) >>> [[next(a_iter) _ in range(n)] n in b] [[1, 2, ... 199, 200], [201, ... 700], [701, 702, ... 999, 1000]]
Comments
Post a Comment