Skip to content

Instantly share code, notes, and snippets.

@victory-sokolov
Created January 6, 2020 12:41
Show Gist options
  • Save victory-sokolov/5c88f1b12c421bb384603c1da5c3e6b2 to your computer and use it in GitHub Desktop.
Save victory-sokolov/5c88f1b12c421bb384603c1da5c3e6b2 to your computer and use it in GitHub Desktop.
Split list into n parts
def chunks(lst, n):
for i in range(0, len(lst), n):
yield lst[i:i + n]
lst = [1,3,5,6,7,9,5,4,2,3,5,6,7,4,3]
res = list(chunks(lst, 3))
print(res) # [[1, 3, 5], [6, 7, 9], [5, 4, 2], [3, 5, 6], [7, 4, 3]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment