Python Forum
is there an itertor of chunks?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is there an itertor of chunks?
#4
Simple one-size

foo = [9,8,7,6,5,4,3,2,1,0]
for i in range(2, len(foo)):
    print(foo[i-2], foo[i-1], foo[i])
or variable size

chunk_size = input('How big do you like your chunks, Hunk? ')
size = int(chunk_size)
   
indexes = [j for j in range(size, 0, -1)]

for i in range(size, len(foo) + 1):
    mylist = []
    for j in indexes:
        num = i-j
        mylist.append(foo[num])
    print(mylist)
BashBedlam likes this post
Reply


Messages In This Thread
is there an itertor of chunks? - by Skaperen - Jul-19-2022, 04:11 AM
RE: is there an itertor of chunks? - by ndc85430 - Jul-19-2022, 04:45 AM
RE: is there an itertor of chunks? - by buran - Jul-19-2022, 05:09 AM
RE: is there an itertor of chunks? - by Pedroski55 - Jul-19-2022, 09:06 AM
RE: is there an itertor of chunks? - by deanhystad - Jul-19-2022, 01:28 PM
RE: is there an itertor of chunks? - by perfringo - Jul-20-2022, 05:49 AM
RE: is there an itertor of chunks? - by Skaperen - Jul-21-2022, 10:40 PM
RE: is there an itertor of chunks? - by deanhystad - Jul-22-2022, 04:06 PM
RE: is there an itertor of chunks? - by Skaperen - Jul-22-2022, 10:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Sad How to split a String from Text Input into 40 char chunks? lastyle 7 1,299 Aug-01-2023, 09:36 AM
Last Post: Pedroski55
  How to scan huge files and make it in chunks ampai 2 2,682 May-28-2020, 08:20 PM
Last Post: micseydel
  how to divide one big equation entered as a string to small chunks gungurbuz 1 1,666 May-28-2020, 03:46 PM
Last Post: Larz60+
  Calling chunks of code The_Taco_King3 3 4,047 Jan-26-2017, 02:54 PM
Last Post: iFunKtion

Forum Jump:

User Panel Messages

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