title: Python working out average scores from a text file
body: <p>I am trying to import data from a text file then work out the average of the 3 scores here is my code so far</p>
  
  <pre><code>for line in fi:
                  column = line.split(",")
                  names = column[0]
                  scores = int(column[1].strip())
  
                  count = 0
                  while count &lt; 3:
                      d.setdefault(names, []).append(scores)
                      count = count + 1
                  averages=[]
          for name, v in d.items():
              average = (sum(v)/len(v))
              averages.append((name, average))
          for name, average in sorted(averages, key=lambda a: a[1], reverse=True):
              print(name, average)
  </code></pre>
  
  <p>This code just prints the first of the 3 scores and doesn't work out the average 
  The file is set out as shown below</p>
  
  <pre><code>andy,2,8,9
  john,4,5,8
  james,9,5,3
  elliot,3,6,2
  Alphie,3,2,4
  </code></pre>
  
  <p>Could anyone help ???     </p>