Jul-19-2022, 04:11 AM
i have a list (or tuple) of many items. here is a very simple case:
what i want to do is step through the list with a step of 1 and a chunk of 3:
1 |
foo = ( 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 ) |
1 2 3 4 5 |
foo = ( 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 ) print ( 'welcome to foo' ) for x in stepchunk(foo, 1 , 3 ): print ( ' ' .join( str (y) for y in x)) print ( 'end of foo' ) |
Output:welcome to foo
9 8 7
8 7 6
7 6 5
6 5 4
5 4 3
4 3 2
3 2 1
2 1 0
end of foo
this can be done with a more complex expression that does its own indexing and slicing (BTDT). i'd like to know if there is some simpler form in the existing library, before i go to write my own. also, what should i name this function if not "stepchunk"? it would be a generator.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.