Created
January 6, 2020 12:41
-
-
Save victory-sokolov/5c88f1b12c421bb384603c1da5c3e6b2 to your computer and use it in GitHub Desktop.
Split list into n parts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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