title: "sort by x (ascending) then by y (descending)" for a csv file in python
body: <p>So I have a csv file that I want to sort using 2 columns (basically the same idea in excel as "sort by somecol then by anothercol").</p>
  
  <p>Given that csvbody is a list of lists generated from the csv file, the way I have it right now that I found from <a href="https://stackoverflow.com/questions/5212870/sorting-a-python-list-by-two-criteria">this question</a> is <code>sortedcsv = sorted(csvbody, key = operator.itemgetter(somecol, anothercol))</code> The issue is that I want to sort by somecol in ascending order and anothercol in descending order. Is there a way to do this (even better, in one line)?</p>
  
  <p>I know that I could do <code>sortedcsv = sorted(csvbody, key = operator.itemgetter(somecol, anothercol), reverse = True)</code> but then it sorts both of them in descending order. Then I tried doing two lines:</p>
  
  <pre><code>sort1 = sorted(csvbody, key = operator.itemgetter(somecol))
  sort2 = sorted(sort1, key = operator.itemgetter(anothercol), reverse = True))
  </code></pre>
  
  <p>However this doesn't work because the second sort just overrides the first sort (it's as if I went into excel and sorted in descending order just by "anothercol")</p>
  
  <p>If you need me to include more information please let me know.</p>