Sorting a list of tuples with 3 elements in python
I have a list of some tuples. Each tuple has three elements. I need to sort the list. To break tie between two tuples, first element of tuple is looked then if still tied then the second element. List is like below. L = [(1, 14, 0), (14, 1, 1), (1, 14, 2), (14, 2, 3), (2, 4, 4), (4, 11, 5), (11, -1000, 6)] In C the sort function takes a compare function and that does everything simply. But I couldn't figure it out after trying for sometimes in python . Can anybody help me? Martijn Pieters Just sort the list; the default sort does just what you want. When comparing two tuples, they are ordered