title: python statistical analysis
body: <p>Given 15 players - 2 Goalkeepers, 5 defenders, 5 midfielders and 3 strikers, and the fact that each has a value and a score, I want to calculate the highest scoring team for the money I have. Each team must consist of 1 GK then a formation e.g. 4:4:2, 4:3:3 etc. I started with sample data such as this  </p>
  
  <p>player role points cost  </p>
  
  <p>I then did the following to evaluate all combinations</p>
  
  <p>read each line into a list (for each role) then use itertools in a nested run to get all combinations  </p>
  
  <pre><code>if line[1] == "G": G.append(line[0])
  if line[1] == "D": D.append(line[0])
  if line[1] == "M": M.append(line[0])
  if line[1] == "S": S.append(line[0])
  
  for gk in itertools.combinations(G,1):
      for de in itertools.combinations(D,4):
          for mi in itertools.combinations(M,4):
              for st in itertools.combinations(S,2):
                  teams[str(count)]= " ".join(gk)+" "+" ".join(de)+" "+" ".join(mi)+" "+" ".join(st)
                  count +=1
  </code></pre>
  
  <p>Having got the teams, I calculate their points value, and the team cost. If it's lower than the threshold, I print it.<br>
  But if I now make this 20 goalkeepers, 150 defenders, 150 midfielders and 100 strikers, I understandably get out of memory.<br>
  What could I do to perform this analysis? Is it a generator rather than a recursive function that I need? </p>
  
  <p>Many thanks</p>