Breaking Python list into set-length list of lists
tjreedy at udel.edu
Thu Feb 12 06:56:07 CET 2009
> I have a list of objects, simply called "list".
> I need to break it
> into an array (list of lists) wherein each sublist is the length of
> the variable "items_per_page". So array would go from array
> to array[items_per_page], then bump up to array - array
> [items_per_page], until all the items in the original list were
> accounted for.
Assuming this is not homework, look at itertools module.
> What would be the simplest way to do this in Python? And yes, I
> realize I should probably be taking Programming 101.....
I guess it is not.
More information about the Python-list