Slicing a list into a list of sub-lists [duplicate]
[input[i:i+n] for i in range(0, len(input), n)] # Use xrange in py2k where n is the length of a chunk. Since you don’t define what might happen to the final element of the new list when the number of elements in input is not divisible by n, I assumed that it’s of no importance: with … Read more