Last active
August 18, 2020 11:08
-
-
Save thuhak/18fdd503d111cfe418685569c4e314da to your computer and use it in GitHub Desktop.
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 cache(iterable, count: int): | |
""" | |
range(10), count=3 -> [0,1,2],[3,4,5],[6,7,8],[9] | |
""" | |
assert(count > 0) | |
saved = [] | |
index = 0 | |
for item in iterable: | |
if index < count: | |
saved.append(item) | |
index += 1 | |
else: | |
yield saved | |
index = 1 | |
saved = [item] | |
yield saved |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment