Nov-30-2016, 05:59 PM
Or, you can wrap what you return in a call to list(), which will exhaust the generator and give a list. Or you can replace the parenthases with square brackets to use a list comprehension instead of a generator comprehension. So the last line of your function would be either...
# wrap in list... return list(I[i:i+n] for i in range(0, len(I), n)) # or, change to a list comprehension... return [I[i:i+n] for i in range(0, len(I), n)]