Created
September 17, 2025 01:30
-
-
Save rlcarrca/e18ec1acce08b3b4155ed9d80349a68f to your computer and use it in GitHub Desktop.
Chunk List
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 batch(seq, size): | |
return [ | |
seq[i:i + size] | |
for i in range(0, len(seq), size) | |
] | |
seq = [1,2,3,4,5,6] | |
size = 3 | |
# OUTPUT: [[1,2,3],[4,5,6]] | |
print(batch(seq, size)) | |
seq = [1,2,3,4,5] | |
size = 2 | |
# OUTPUT: [[1,2],[3,4],[5]] | |
print(batch(seq, size)) | |
seq = [1,2,3] | |
size = 4 | |
# OUTPUT: [[1,2,3]] | |
print(batch(seq, size)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment