From nosklo's answer in What is the most “pythonic” way to iterate over a list in chunks? what is the return line doing:
def chunker(seq, size):
return (seq[pos:pos + size] for pos in range(0, len(seq), size))
I understand what the output will be, I'd just like to know how this works.
EDIT: Adding use case to hopefully clear up confusion.
I am using the defined function to read in a list of unknown size and grab 8 objects from it, run those 8 through something, and then grab the next 8 and so forth until the list is completed. Use case from nosklo's post:
animals = ['cat', 'dog', 'rabbit', 'duck', 'bird', 'cow', 'gnu', 'fish']
for group in chunker(animals, 3):
print group
# ['cat', 'dog', 'rabbit']
# ['duck', 'bird', 'cow']
# ['gnu', 'fish']