Let’s see how we can split a list into chunks in Python.
import numpy as np # create a list x = [1,2,3,4,5,6,7,8,9,10,11] # target elements n = 5 output = [list(lst) for lst in np.array_split(x, np.ceil(len(x)/n))] output
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11]]