title: Python, Sorting averages
body: <p>I have half a problem with sorting data from a text file. I am suppose to find the average from 3 numbers which are weighted and print out which name within the text file that particular average belongs to. </p>
  
  <p>I have managed to do this for the highest average but I have had a few problems finding the lowest average.</p>
  
  <p>Sample text from the file.</p>
  
  <pre><code>Shoes 210 130 67
  Bags  167 321 459
  </code></pre>
  
  <p>Position 0 in the text file is the name of the department. Position 1 in the file is 'Good Votes'. Position 2 'Fair Votes'. Position 3 'Poor Votes'.</p>
  
  <p>The highest average in the list is Shoes with an average of 2.351 and the lowest average in the list is Bags with an average of 1.692.</p>
  
  <p>I have defined a function to calculate the average and have called it without any problems for the highest average.</p>
  
  <pre><code>highestAverage = 0
      highestAvgDepName = 0      
      if choice2 == 1:
          calculateAverage(allDepartments,choice2)
          for x in range (10):
              if highestAverage &lt; calculateAverage(allDepartments, x):
                  highestAverage = calculateAverage(allDepartments, x)
                  highestAvgDepName = x
  </code></pre>
  
  <p>The only issue I have is getting this to find the lowest average. I have tried creating a new function that calculates the average and multiplies it by -1 turning all the numbers negative, which should technically make the largest number -1.692 but it throws me 55.***. </p>
  
  <p>I have looked into bubble sorting, however, I don't understand how to do that from a text file.</p>
  
  <pre><code>def calculateAverage(allDepartments, choice2):
  total = allDepartments[choice2][1] + allDepartments[choice2][2] + allDepartments[choice2][3]
  return((allDepartments[choice2][1]*3 + allDepartments[choice2][2]*2 + allDepartments[choice2][3])/total)
  </code></pre>