Last active
December 3, 2019 03:48
-
-
Save vietvudanh/dfbc689306ed724d29b6439521161d97 to your computer and use it in GitHub Desktop.
data snippets
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(l, n): | |
"""Yield successive n-sized chunks from l.""" | |
for i in range(0, len(l), n): | |
yield l[i:i + n] | |
def chunks_iter(l, n): | |
it = iter(iterable) | |
while True: | |
chunk = tuple(itertools.islice(it, n)) | |
if not chunk: | |
return | |
yield chunk | |
def range_generator(upper, batch_size): | |
"""Yield successive n-sized chunks from l.""" | |
return [ | |
(i, i + batch_size) | |
for i in range(0, upper, batch_size) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment