Good day function-wizards,
I want an algorithm to iterate over list slices. Slices size is set outside the function and can differ.
In my mind it is something like:
for list_of_x_items in fatherList:
foo(list_of_x_items)
Is there a way to properly define list_of_x_items
or some other way of doing this?
Thank you greatly.
PS: using python 2.5
edit1: So many beautiful answers.. Someone has asked to clarify. Both "partitioning" and "sliding window" terms sound applicable to my task, but I am no expert. So I will explain the problem a bit deeper and add to the question:
The fatherList is a multilevel numpy.array I am getting from a file. Function has to find averages of series (user provides the length of series) For averaging I am using the mean()
function. Now for question expansion:
question update: How to modify the function you have provided to store the extra items and use them when the next fatherList is fed to the function?
for example if the list is lenght 10 and size of a chunk is 3, then the 10th member of the list is stored and appended to the beginning of the next list.
Hope I am not assaulting anyone by not creating a separate question.
edit2: Ah, SO will you marry me? Many beautiful answers and only one to choose.. Thank you everyone, I've learned more from this question than from a month of my university studies. I am choosing the OO answer because it will allow me more flexibility in the future.