This is a job for itemgetter

>>> from operator import itemgetter
>>> L=[[0, 1, 'f'], [4, 2, 't'], [9, 4, 'afsd']]
>>> sorted(L, key=itemgetter(2))
[[9, 4, 'afsd'], [0, 1, 'f'], [4, 2, 't']]

It is also possible to use a lambda function here, however the lambda function is slower in this simple case

Answer from John La Rooy on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-sorting-list-of-lists-with-similar-list-elements
Python | Sorting list of lists with similar list elements - GeeksforGeeks
April 17, 2023 - We assign the resulting sorted list of lists to the variable res. Finally, we print the resulting sorted list res using the print() function and the str() function to convert the list to a string for printing purposes. ... # Python3 code to demonstrate # Sorting list of lists with similar list elements # using list comprehension + sorted() # initializing list test_list = [[[4, 4], [1, 1]], [[3, 3], [2, 2], [5, 5]]] # printing original list print("The original list : " + str(test_list)) # using list comprehension + sorted() # Sorting list of lists with similar list elements res = [sorted(idx) for idx in test_list] # print result print("The list after performing sort operation : " + str(res))
Discussions

Sorting list of lists
I’m working with lists. I need to sort by one of the values in the sub list. I need the whole sub list to move with the value that is being sorted. Example data: files = [asb, 23, 89], [asc, 48, 89], [asa, 78, 89] # Th… More on discuss.python.org
🌐 discuss.python.org
8
0
December 27, 2022
How do I sort a list with sublists with multiple ascending and descending criteria?
I've figured it out. At first I tried -abs(i[0]) but I didn't realize that -|negative number| is still a negative number, so of course the sorting is not going to work. I came up with -i[0] just before I write this post and that's exactly what I need, but I didn't actually test it out myself before posting, so I'm sorry about that. Thanks everyone for helping. Have a great day. More on reddit.com
🌐 r/learnpython
9
2
October 12, 2023
PySpark - How to deal with list of lists as a column of a dataframe
Hello! I'm a bot! It looks to me like your post might be better suited for r/learnpython , a sub geared towards questions and learning more about python regardless of how advanced your question might be. That said, I am a bot and it is hard to tell. I'm sure you've seen this information before, but just in case here it is as a reminder: Please follow the subs rules and guidelines when you do post there, it'll help you get better answers faster. Show r/learnpython the code you have tried and describe in detail where you are stuck. If you are getting an error message, include the full block of text it spits out. Quality answers take time to write out, and many times other users will need to ask clarifying questions. Be patient and help them help you. Here is HOW TO FORMAT YOUR CODE For Reddit and be sure to include which version of python and what OS you are using. You can also ask this question in the Python discord , a large, friendly community focused around the Python programming language, open to those who wish to learn the language or improve their skills, as well as those looking to help others. README | FAQ | this bot is written and managed by u/IAmKindOfCreative This bot is currently under development and experiencing changes to improve its usefulness More on reddit.com
🌐 r/Python
1
1
March 30, 2020
[Haskell] Finding the shortest list in a list of lists
You might also consider the approach which relies on standard library functions: import Data.Ord import Data.List shortest = minimumBy (comparing length) Edit: If you use a recent base (4.8.0.0 or newer), you could instead use sortOn and define shortest = head . sortOn length; this has the advantage of not recomputing length. More on reddit.com
🌐 r/haskellquestions
12
4
October 11, 2015
🌐
Mimo
mimo.org › glossary › python › list-sort()
Python List sort(): Master Data Sorting | Learn Now
The Python sort() method organizes the elements of a list in ascending or descending order.
🌐
Devzery
devzery.com › post › your-ultimate-guide-to-sorting-a-list-of-lists-in-python
Your Ultimate Guide to Sorting a List of Lists in Python
July 25, 2024 - In this example, the list is sorted by the third element (index 2) of each inner list. The sort() method sorts the list in place and modifies the original list. ... This has the same effect as the sorted() function but modifies data directly.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-sort-list-of-lists-by-the-size-of-sublists
Python - Sort List of Lists by the Size of Sublists - GeeksforGeeks
January 28, 2026 - This method sorts the original list using sort() directly in place based on the length of each sublist in ascending order.
Find elsewhere
🌐
Python Central
pythoncentral.io › how-to-sort-a-list-in-python
How to Sort A List in Python | Python Central
December 29, 2021 - Furthermore, it can be used without any parameters, similar to sort(). By default, the function arranges data in ascending order. However, unlike sort(), the sorted() function stores the arranged values in a new list.
🌐
W3Schools
w3schools.com › python › python_lists_loop.asp
Python - Loop Lists
Python DSA Lists and Arrays Stacks Queues Linked Lists Hash Tables Trees Binary Trees Binary Search Trees AVL Trees Graphs Linear Search Binary Search Bubble Sort Selection Sort Insertion Sort Quick Sort Counting Sort Radix Sort Merge Sort
🌐
Plain English
python.plainenglish.io › sorting-a-list-of-lists-in-python-8478b2ac5b12
Sorting a List of Lists in Python | by Allwin Raju | Python in Plain English
November 26, 2024 - Sorting a List of Lists in Python Sorting is one of the most common tasks in programming, and Python makes it incredibly easy to sort simple lists and more complex structures like lists of lists. In …
🌐
SpeedySense
speedysense.com › home › python › python list sorting with sorted() and sort()
Python List Sorting with sorted() and sort() - SpeedySense
October 20, 2019 - However, before we start ahead, you need to understanding python lists, and tuples. The sort() method sorts the elements of a given list in a specific order (Ascending or Descending).
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python sort list of lists
Python Sort List of Lists - Spark By {Examples}
May 31, 2024 - How to sort a list of lists in python? Sorting a list of lists in Python is a powerful feature that allows you to sort the inner lists based on a specific
🌐
Reddit
reddit.com › r/learnpython › how do i sort a list with sublists with multiple ascending and descending criteria?
r/learnpython on Reddit: How do I sort a list with sublists with multiple ascending and descending criteria?
October 12, 2023 -

For example, if I have a list :

list = [ [-10, 1, 3], [2, -5, 29], [3, -5, 0], [0, 0, -1] ]

And I want to sort the list with the following criteria in order :

For i in list :

  1. sort i[2] (in ascending order)

  2. sort i[0] (in descending order)

  3. sort i[1] (in ascending order)

I've tried rearranging by using list comprehension and *-1 on the index I want to sort in descending order, then sort the rearranged list ( ex : newlist = [ [i[2], -i[0], i[1]] for i in list ] then newlist.sort() ) However, *-1 for descending order doesn’t work since some numbers are already negative, so that’s like where I’m stuck with. Any idea how to do this?

By the way, I cannot use dict, numpy, tuple, set or import any libraries since this is my college homework and my professor doesn’t allow us to use any of those.

🌐
Big-O Cheat Sheet
bigocheatsheet.com
Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell
This webpage covers the space and time Big-O complexities of common algorithms used in Computer Science. When preparing for technical interviews in the past, I found myself spending hours crawling the internet putting together the best, average, and worst case complexities for search and sorting ...
🌐
Python Pool
pythonpool.com › home › blog › 6 unique ways in python to sort the list of lists
6 Unique Ways in Python to Sort the List of Lists - Python Pool
June 14, 2021 - There are many ways to sort a list of lists in python. We can sort by length of elements, the sum of lists in ascending and descending order.
🌐
Indiachinainstitute
indiachinainstitute.org › wp-content › uploads › 2018 › 05 › Python-Crash-Course.pdf pdf
Python crash course
Sorting a List Temporarily with the sorted() Function . . . . . . . . . . . . . . . . . . . . 48 · Printing a List in Reverse Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 · Finding the Length of a List . . . . . . . . . . . . . . .
🌐
Programiz
programiz.com › python-programming › methods › list › sort
Python List sort()
The sort() method sorts the elements of a list in ascending order. In this tutorial, we will learn about the Python sort() method with the help of examples.
🌐
Pierian Training
pieriantraining.com › home › python list sorting: sort() and sorted()
Python List Sorting: sort() and sorted() - Pierian Training
June 18, 2023 - It can also be used with custom ... conclusion, sorting lists in Python is a common task that can be achieved using the built-in `sort()` function....
🌐
Real Python
realpython.com › python-dicts
Dictionaries in Python – Real Python
2 weeks ago - The sorted() function returns a list of sorted values, so you wrap its call with dict() to build a new sorted dictionary. In the first call, you sort the items by value in ascending order.