title: Dividing array into chunks of almost equal sum
body: <p>The code for dividing the chunks is provided by this code snippet:</p>
  <pre><code>def chunks(lst, n):     #n here is 4
      &quot;&quot;&quot;Yield successive n-sized chunks from lst.&quot;&quot;&quot;
      for i in range(0, len(lst), n):
          yield lst[i:i + n]
  </code></pre>
  <p>As an input I have a list with the following integers:</p>
  <pre><code>[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]
  </code></pre>
  <p>I want to generate 4 chunks with that. As an output i get the following:</p>
  <pre><code>[[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]]
  </code></pre>
  <p>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.<br />
  Can anyone give me an idea how to get a fair distribution of the numbers in the chunks by including the integers?</p>
  <p>I've done an example by hand:</p>
  <p>Input: <code>[11,20,2,4,8,13,16,0,1,0,3,6]</code></p>
  <p>Output: <code>[[20,1,0,0],[16,6],[13,8],[11,4,3,2]]</code></p>