title: How to sort items by column from a text file in python
body: <p>I have the following items in a text file with names of cities and there quarter revenues:</p>
  
  <pre><code> Atlanta   40 50 23 18
   Denver    56 78 34 11
   Miami     40 34 18 30
   Orlando   55 67 23 11
   Memphis   44 23 56 11
   Boston    55 67 33 23
   Tampa     45 67 54 77
  </code></pre>
  
  <p>I am having issues with sorting the quarter revenues in the list. My current program looks like this.</p>
  
  <pre><code>with open('revenue.txt', 'r') as f:
  text = [line.split() for line in f]
  print("{:&lt;12}{:&lt;14}{:&gt;10}{:&gt;9}".format("City", "Revenue", "Total", 
  "Average"))
  for a in text:
      city = a[0]
      revenue = [int(i) for i in a[1:5]]
      total = sum(revenue)
      avg = sum(revenue)/len(revenue)
      print("{:&lt;12}{}{:&gt;6}{:&gt;9.2f}".format(city, revenue, total, avg))
  
  print("\n""Sort the cities by their Quarter 1 revenues.")
  
  print("\n""Sort the cities by their Quarter 3 revenues.")
  
  print("\n""Sort the cities by their total revenues.")
  </code></pre>
  
  <p>I am trying to figure out how I can sort 1st quarter, 3rd quarter,and total columns and then print the city that is associated with them. For example:</p>
  
  <pre><code>Sort the cities by their Quarter 1 revenues
  ['Miami','Atlanta','Memphis','Tampa','Boston','Orlando','Denver']
  #  [40,40,44,45,55,55,56]
  </code></pre>
  
  <p>Any help will be appreciated.</p>