What's the best python idiom for grouping a list of items into groups of a specific max size? -
I want to type a function that takes the item from the list and creates a group in the size n group.
For Ie, n = 5, [1, 2, 3, 4, 5, 6, 7] [[1, 2, 3, 4, 5], [6, 7] Will go
What is the best idol of Python to do this?
I do not know a good command to do this, but to understand it with a list of One way:
l = [1,2,3,4,5,6,7] n = 5 new list = [in the range for [i: i + n] (0, Lane (L), N)] Edit: As a commentator has been told, I accidentally put [i: I + n] in a list.
Comments
Post a Comment