I'm looking to run an operation on all values of a list but 10 at a time. The problem is that on the final cycle of the for loop there are less than 10 values in the list. My current solution to this is to do the following:
for i in range(len(my_list) // 10):
for i in range(10):
# do operation
for i in range(len(my_list) % 10):
# do operation
Or another solution would be:
while True:
for i in range(10):
if not my_list:
break
# do operation
if not my_list:
break
My question is if there's a better (and probably quite obvious) solution to this. I wasn't sure how to describe the issue, so there may be another question that already answers this if I had known the right terminology to look with. Sorry if this is the case.