Skip to content

Instantly share code, notes, and snippets.

@ftorto
Created January 24, 2017 10:24
Show Gist options
  • Save ftorto/026c3d91fc66a571b923a8a9cf3d6df4 to your computer and use it in GitHub Desktop.
Save ftorto/026c3d91fc66a571b923a8a9cf3d6df4 to your computer and use it in GitHub Desktop.
Split a list in chunk with python
list_to_chunk = [1,2,3,4,5,6,7,8,9,10]
number_of_items_per_chunk = 2
for i in range(0, len(list_to_chunk), number_of_items_per_chunk):
print("CHUNK %s"%i)
chunk = list_to_chunk[i:i + number_of_items_per_chunk]
# Action to perform on each chunk here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment