How do you split a list into evenly sized chunks?

Here’s a generator that yields the chunks you want: If you’re using Python 2, you should use xrange() instead of range(): Also you can simply use list comprehension instead of writing a function, though it’s a good idea to encapsulate operations like this in named functions so that your code is easier to understand. Python 3: Python 2 … Read more

Here’s a generator that yields the chunks you want: If you’re using Python 2, you should use xrange() instead of range(): Also you can simply use list comprehension instead of writing a function, though it’s a good idea to encapsulate operations like this in named functions so that your code is easier to understand. Python 3: Python 2 … Read more