Skip to content

Instantly share code, notes, and snippets.

@seozed
Created January 15, 2020 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seozed/0b651918cc9286643e101a90e514ed78 to your computer and use it in GitHub Desktop.
Save seozed/0b651918cc9286643e101a90e514ed78 to your computer and use it in GitHub Desktop.
对可迭代的对象进行分块
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