Breaking Python list into set-length list of lists

Jason elgrandchignon at gmail.com
Wed Feb 11 23:58:28 EST 2009


Hey everyone--

I'm pretty new to Python, & I need to do something that's incredibly
simple, but combing my Python Cookbook & googling hasn't helped me out
too much yet, and my brain is very, very tired & flaccid @ the
moment....

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[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.

What would be the simplest way to do this in Python?  And yes, I
realize I should probably be taking Programming 101.....



More information about the Python-list mailing list