Let's remember this
split_list(l, n)
#l:list
#n:Number of elements in the sublist
I'll break the list
def split_list(l, n):
for idx in range(0, len(l), n):
yield l[idx:idx + n]
l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] #Original list
result = list(split_list(l, 3)) #How many elements to divide
print(result) # [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]
Recommended Posts