Last active
January 13, 2019 18:51
-
-
Save vitalysim/7d937fe379d4a8fcd4af2a97f024b462 to your computer and use it in GitHub Desktop.
This file contains 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
# Divide list into chunks containing n element | |
def divide_chunks(l, n_elements): | |
for i in range(0, len(l), n_elements): | |
yield l[i:i + n_elements] | |
if __name__ == "__main__": | |
n = [1,2,3,4,5,6,7,8,9,10,12,13,14,15] | |
for chunck in divide_chunks(n, 5): | |
print(chunck) | |
# Output: | |
# [1, 2, 3, 4, 5] | |
# [6, 7, 8, 9, 10] | |
# [12, 13, 14, 15] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment