I have a list as input, like this:
lst = [1, 10, 100, 2, 20, 200, 3, 30, 300]
Every three element is a subgroup, and I want to split them into subgroups, like this:
lst[0:3] # => [1,10,100]
lst[4:6] # => [2,20,200]
lst[7:9] # => [3,30,300]
What is the elegant way of doing it?
I only find this: Split list into smaller lists
I can certainly achieve this by the code about, but this falls short when the input comes with more arguments, like
lst = [1, 10, 100, 2, 20, 200, 3, 30, 300, 4, 40, 400, 5, 50, 500 ...]
I think maybe reshape()
would be a good way?