Last active
May 8, 2018 22:42
-
-
Save AlmightyOatmeal/ae00f1beee2598c80efe3e9dbea805bd to your computer and use it in GitHub Desktop.
Fun with Python lists! Works on Python 2.7.x.
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 list_chunker(list_obj, chunk_size): | |
"""Break apart a list into smaller lists as a generator. | |
:param list_obj: Array of single values in which to be chunkersized. | |
:type list_obj: list or set | |
:param chunk_size: Size of the resulting generated lists. | |
:type chunk_size: int | |
:return: List of the specified size or last remaining items. | |
:rtype: list | |
""" | |
[(yield list_obj[x:x+chunk_size]) for x in range(0, len(list_obj), chunk_size)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment