Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list_split
#4
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)]
Reply


Messages In This Thread
list_split - by roadrage - Nov-29-2016, 05:30 PM
RE: list_split - by micseydel - Nov-29-2016, 05:53 PM
RE: list_split - by heiner55 - Nov-29-2016, 06:12 PM
RE: list_split - by nilamo - Nov-30-2016, 05:59 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020