title: Python 3 Sorting a List of Tuples?
body: <p>I am a Python newbie and I have a question. I was told to ask this separately from another post I made for the same program. This is homework, so I would just like some guidance. I have a list of tuples, and I want to sort it by tuple[0] and return the full tuple for use in printing to the screen. The tuples are made up of (score,mark(x or o),index)</p>
  
  <p>Here is my basic code (part of a tic tac toe game- I have the full code in another post):::</p>
  
  <pre><code>listOfScores = miniMax(gameBoard)
  best = max(listOfScores, key=lambda x: x[0])
  
  if best[0] == 0:
              print("You should mark " + best[1] + " in cell " + best[2] + ".")
              print("This will lead to a tie.")
          elif best[0] &gt; 0:
              print("You should mark " + best[1] + " in cell " + best[2] + ".")
              print("This will lead to a win.")
          else:
              print("You should mark " + best[1] + " in cell " + best[2] + ".")
              print("This will lead to a loss.")
  </code></pre>
  
  <p>I am getting this error:::</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\Abby\Desktop\CS 3610\hw2\hw2Copy.py", line 134, in &lt;module&gt;
      main()
    File "C:\Users\Abby\Desktop\CS 3610\hw2\hw2Copy.py", line 120, in main
      best = max(listOfScores, key=lambda x: x[0])
  TypeError: unorderable types: list() &gt; int()
  </code></pre>
  
  <p>I'm not sure why this is happening. This is my first time trying to use this:</p>
  
  <pre><code>best = max(listOfScores, key=lambda x: x[0])
  </code></pre>
  
  <p>so I think that maybe I am using it incorrectly. Is there a better way to sort these tuples (from largest to smallest, and smallest to largest), so that I can retrieve either the smallest or largest value? Thank you! :)</p>