Created
January 8, 2019 02:57
-
-
Save ridingintraffic/b4a751b84dbc217cd1d9ee079bbc1e21 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
<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