Breaking Python list into set-length list of lists

Terry Reedy tjreedy at udel.edu
Thu Feb 12 06:56:07 CET 2009


Jason wrote:

> I have a list of objects, simply called "list".

Bad idea.

>  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[0] would go from array[0][0]
> to array[0][items_per_page], then bump up to array[1][0] - array[1]
> [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 mailing list