title: Algorithm for generating a bracket model list in Python
body: <p>I'm trying to make a simple recursive function that will generate a list of nested lists in Python.  The end result will represent a single elimination tournament bracket.  I'm hoping that creating a list like this will make it easy for me to generate what I need.  This will later be used to create models for tournament matches.</p>
  
  <p>So if there is a tournament of 4 participants:</p>
  
  <pre><code>[[1,4],[2,3]]
  </code></pre>
  
  <p>Tournament of 7 participants:</p>
  
  <pre><code>[[1,[4,5]],[[2,7],[3,6]]]
  </code></pre>
  
  <p>Or a tournament of 8 participants:</p>
  
  <pre><code>[[[1,8],[4,5]],[[2,7],[3,6]]]
  </code></pre>
  
  <p>I haven't had an algorithms class yet (I'm hoping the class will end up helping with things like this) so I'm not completely sure how to approach this problem.  Below is my attempt so far.</p>
  
  <pre><code>def decide_rounds(list_to_fill, player_nums):
      if len(player_nums) &lt; 3:
          for num in player_nums:
              list_to_fill.append(num)
          return
  
      left = []
      decide_rounds(left, ??????) #Tried passing various things to these with no avail.
      list_to_fill.append(left)
      right = []
      decide_rounds(right, ???????)
      list_to_fill.append(right)
  </code></pre>
  
  <p>Any help or explanation on how to approach this would be greatly appreciated!</p>
  
  <p>Edit: Currently I am calling the function like this:</p>
  
  <pre><code>rounds = []
  decide_rounds(rounds, range(1, size +1))
  print rounds
  </code></pre>