The code for dividing the chunks is provided by this code snippet:
def chunks(lst, n): #n here is 4
"""Yield successive n-sized chunks from lst."""
for i in range(0, len(lst), n):
yield lst[i:i + n]
As an input I have a list with the following integers:
[11, 45, 74, 24, 27, 55, 37, 97, 15, 36, 54, 7, 41, 77, 28, 36, 22, 214, 110, 40, 41, 14, 6, 35, 6, 7, 62, 2, 34, 1, 30, 5, 4, 8, 9, 7, 5, 7, 0, 0, 3, 0, 0, 1, 2]
I want to generate 4 chunks with that. As an output i get the following:
[[11, 45, 74, 24, 27, 55, 37, 97, 15, 36, 54, 7],
[41, 77, 28, 36, 22, 214, 110, 40, 41, 14, 6, 35],
[6, 7, 62, 2, 34, 1, 30, 5, 4, 8, 9, 7],
[5, 7, 0, 0, 3, 0, 0, 1, 2]]
My problem is that the second list in the output has a higher weight than the other ones; the distribution of the numbers is not quite fair.
Can anyone give me an idea how to get a fair distribution of the numbers in the chunks by including the integers?
I've done an example by hand:
Input: [11,20,2,4,8,13,16,0,1,0,3,6]
Output: [[20,1,0,0],[16,6],[13,8],[11,4,3,2]]