Answer the question
In order to leave comments, you need to log in
How to sort list of tuples in python?
How to sort a list of tuples by the first element of the tuple?
For example, there is
list1 = [(13, 5, 7), (0, 23, 1), (7, 4, 3)]
It needs to become
list2 = [(0, 23, 1), (7, 4, 3) , (13, 5, 7)]
Answer the question
In order to leave comments, you need to log in
And now the correct one:
from operator import itemgetter
list2 = sorted(list1, key=itemgetter(0))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question