Skip to content

Instantly share code, notes, and snippets.

@ridingintraffic
Created January 8, 2019 02:57
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 ridingintraffic/b4a751b84dbc217cd1d9ee079bbc1e21 to your computer and use it in GitHub Desktop.
Save ridingintraffic/b4a751b84dbc217cd1d9ee079bbc1e21 to your computer and use it in GitHub Desktop.
<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