This question already has an answer here:
I have a list contains many elements. I want to slice it every 100 elements to a list of several lists.
For example:
>>> a = range(256)
>>> b = slice(a, 100)
b
should then be [[0,1,2,...99],[100,101,102,...199],[200,201,...,255]]
.
What's the most pythonic and elegent way to do that?
This should do the trick:
range
takes an optional thirdstep
argument, sorange(0, n, 100)
will be0, 100, 200, ...
.