Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<begin python script>
# test.py
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
all_ids = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
chunked_list_ids=chunks(all_ids,5)
print chunked_list_ids
for list_temp in chunked_list_ids:
print list_temp
<end python script>
$
$
$ python test.py
<generator object chunks at 0x1069bea50>
[1, 2, 3, 4, 5]
[6, 7, 8, 9, 10]
[11, 12, 13, 14, 15]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.