title: Algorithm to Divide a list of numbers into 2 equal sum lists
body: <blockquote>
  <p>There is a list of numbers.<br />
  The list is to be divided into 2 equal sized lists, with a minimal difference in sum. The sums have to be printed.</p>
  <pre><code>#Example:
  &gt;&gt;&gt;que = [2,3,10,5,8,9,7,3,5,2]
  &gt;&gt;&gt;make_teams(que)
  27 27
  </code></pre>
  </blockquote>
  <p>Is there an error in the following code algorithm for some case?</p>
  <p>How do I optimize and/or pythonize this?</p>
  <pre><code>def make_teams(que):
      que.sort()
      if len(que)%2: que.insert(0,0)
      t1,t2 = [],[]
      while que:
          val = (que.pop(), que.pop())
          if sum(t1)&gt;sum(t2):
              t2.append(val[0])
              t1.append(val[1])
          else:
              t1.append(val[0])
              t2.append(val[1])
      print min(sum(t1),sum(t2)), max(sum(t1),sum(t2)), &quot;\n&quot;
  </code></pre>
  <p>Question is from <a href="http://www.codechef.com/problems/TEAMSEL/" rel="nofollow noreferrer">http://www.codechef.com/problems/TEAMSEL/</a></p>