title: Fair partitioning of elements of a list
body: <p>Given a list of ratings of players, I am required to partition the players (ie ratings) into two groups as fairly as possible. The goal is to minimize the difference between the teams' cumulative rating. There are no constraints as to how I can split the players into the teams (one team can have 2 players and the other team can have 10 players).</p>
  
  <p>For example: <code>[5, 6, 2, 10, 2, 3, 4]</code> should return <code>([6, 5, 3, 2], [10, 4, 2])</code></p>
  
  <p>I would like to know the algorithm to solve this problem. Please note I am taking an online programming introductory course, so simple algorithms would be appreciated.</p>
  
  <p>I am using the following code, but for some reason, the online code checker says it is incorrect.</p>
  
  <pre><code>def partition(ratings):
      set1 = []
      set2 =[]
      sum_1 = 0
      sum_2 = 0
      for n in sorted(ratings, reverse=True):
          if sum_1 &lt; sum_2:
              set1.append(n)
              sum_1 = sum_1 + n
          else:
              set2.append(n)
              sum_2 = sum_2 + n
      return(set1, set2)
  </code></pre>
  
  <p><strong>Update:</strong> I contacted the instructors and I was told I should defined another "helper" function inside the function to check all different combinations then I need to check for the minimum difference.</p>