Split a List Into Evenly Sized Chunks in Python Using for Loop

Split a List Into Evenly Sized Chunks in Python Using for Loop
(Last Updated On: 10/02/2023)

Python Program to Split a List Into Evenly Sized Chunks Using for Loop

# Python Program to Split a List Into Evenly Sized Chunks Using for Loop

my_list = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
start = 0
end = len(my_list)
step = 3
for i in range(start, end, step):
	x = i
	print(my_list[x:x+step])

Output:

[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
[10, 11, 12]
[13, 14, 15]

Leave a Reply

Your email address will not be published. Required fields are marked *