I have a list of 200 elements, i want to loop through the list in increments of 10.
- Result 1 = list[0:10]
- Result 2 = list[11:21]
- Result 3 = list[22:32]
- Result 20 = list[190:199]
Whats the most pythonic way to do this?
I have a list of 200 elements, i want to loop through the list in increments of 10.
Whats the most pythonic way to do this?
You have to split your list into chunks:
chunks = [xlist[x:x+10] for x in range(0, len(xlist), 10)]
for chunk in chunks:
print(len (chunk)) # prints out 10