Pagination

by: kingcool52, 7 years ago


I saw one of your posts in the community section regarding creating our own pagination with Flask. I'm slightly confused about this part:

"Then I just grab thread ids in descending time order, and sort them into a list of lists, where it's a list of lists, where the lists contain 10 desc ordered thread ids.."

How would I place the items into a list of lists with each list having 10 items?



You must be logged in to post. Please login or register an account.



Here's a fantastic way:

def chunks(l, n):
    """Yield successive n-sized chunks from l."""
    for i in xrange(0, len(l), n):
        yield l[i:i + n]

Source:
https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks

-Harrison 7 years ago
Last edited 7 years ago

You must be logged in to post. Please login or register an account.