title: How to get only top 5 and bottom 5 lists from Nested list?
body: <p>So right I'm working with a file with a bunch of lists within a list. I'm trying to arrange them by top 5 states and bottom 5 states for total number of participants.</p>
  
  <pre><code>import csv
  from operator import itemgetter #not really using this right now
  crimefile = open('APExam.txt', 'r')
  reader = csv.reader(crimefile)
  allRows = [row for row in reader]
  L = sorted(allRows,key=lambda x: x[1])
  for item in L:
      print item[0],','.join(map(str,item[1:]))
  </code></pre>
  
  <p>Which prints something like this:</p>
  
  <pre><code>State  Total #,% passed,%female
  Wyoming 0,0,0
  New Hampshire 101,76,12
  Utah 103,54,4
  Mass 1067,67,18
  Montana 11,55,0
  Iowa 118,80,9
  Alabama 126,79,17
  Georgia 1261,51,18
  Florida 1521,44,20
  Illinois 1559,69,13
  New Jersey 1582,74,15
  Maine 161,67,16
  </code></pre>
  
  <p>This prints the file in a way that is nearly what I'm looking for but the total number of participants isn't sorted by the largest to lowest; it is sorted by looking at the first element. How do I change it to look more like:</p>
  
  <pre><code>New Jersey 1582,74,15
  Illinois 1559,69,13
  Florida 1521,44,20
  Georgia 1261,51,18
  Etc...
  </code></pre>
  
  <p>First time asking a question here, any help is appreciated! :) Also, I'm trying not to use the .sort() or find() function or the "in" operator-- such as "if 6 in [5, 4, 7 6] ..."</p>
  
  <p>Edit*: By changing L</p>
  
  <pre><code>L = sorted(allRows,key=lambda x: int(x[1]),reverse=True)
  </code></pre>
  
  <p>I've gotten to the point where I have the list going in descending order:</p>
  
  <pre><code>State  Total #,% passed,%female
  California 4964,76,22
  Texas 3979,62,23
  New York 1858,69,20
  Virginia 1655,60,19
  Maryland 1629,66,20
  New Jersey 1582,74,15
  Illinois 1559,69,13
  Florida 1521,44,20
  </code></pre>
  
  <p>Now I can't quite seem to figure out how to only take the top 5 and bottom 5 based on these totals...</p>