Created
January 15, 2020 03:05
-
-
Save seozed/0b651918cc9286643e101a90e514ed78 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 chunked(iterable, n): | |
from itertools import islice | |
from functools import partial | |
def take(n, iterable): | |
return list(islice(iterable, n)) | |
return iter(partial(take, n, iter(iterable)), []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment