title: Sorting a csv file (Python)
body: <p>I have this piece of code written to sort a csv file in Python.</p>
  
  <pre><code>import csv
  from operator import itemgetter
  reader = csv.reader(open("highscores.txt"), delimiter=",")
  sortedList = sorted(reader, key=itemgetter(1), reverse=True)
  print(sortedList)
  </code></pre>
  
  <p>I am trying the sort the file by the second item in the array, for example if in my file I had:</p>
  
  <pre><code>Callum,22
  Kim,43
  </code></pre>
  
  <p>It would sort it to:</p>
  
  <pre><code>Kim,43
  Callum,22
  </code></pre>
  
  <p>However when I run my program I get the error message:</p>
  
  <pre><code>sortedList = sorted(reader, key=itemgetter(1), reverse=True)
  IndexError: list index out of range
  </code></pre>
  
  <p>Edit:</p>
  
  <p>I have solved this issue, the problem wasn't the sort function itself but it was a problem with the file that only worked in python 2.7 for some reason.</p>