If you are using numpy, you have the argsort() function available:

>>> import numpy
>>> numpy.argsort(myList)
array([0, 1, 2, 4, 3])

http://docs.scipy.org/doc/numpy/reference/generated/numpy.argsort.html

This returns the arguments that would sort the array or list.

Answer from Matthew Lewis on Stack Overflow
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.DataFrame.sort_index.html
pandas.DataFrame.sort_index โ€” pandas 3.0.1 documentation
Sort ascending vs. descending. When the index is a MultiIndex the sort direction can be controlled for each level individually.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ howto โ€บ sorting.html
Sorting Techniques โ€” Python 3.14.3 documentation
February 23, 2026 - Author, Andrew Dalke and Raymond Hettinger,. Python lists have a built-in list.sort() method that modifies the list in-place. There is also a sorted() built-in function that builds a new sorted lis...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-sort-list-of-list-by-specified-index
Python - Sort list of list by specified index - GeeksforGeeks
July 11, 2025 - The most simple and efficient way to sort a list of lists by a specified index is using the sorted() function with a key. It is efficient and concise for sorting by any index. ... a = [[1, 'Python', 50], [2, 'with', 30], [3, 'GFG', 40]] # Sorting ...
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ third-party โ€บ numpy โ€บ argsort
Python Numpy argsort() - Sort Array Indices | Vultr Docs
November 11, 2024 - This code snippet sorts the data array and returns the indices that sort the array.
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.argsort.html
numpy.argsort โ€” NumPy v2.5.dev0 Manual
Array of indices that sort a along the specified axis. If a is one-dimensional, a[index_array] yields a sorted a.
Find elsewhere
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ pandas โ€บ sort
Pandas Sort (With Examples)
The sort_index() function is used to sort a DataFrame or Series by its index. This is useful for organizing data in a logical order, improving query performance, and ensuring consistent data representation.
๐ŸŒ
Google
developers.google.com โ€บ google for education โ€บ python โ€บ python sorting
Python Sorting | Python Education | Google for Developers
The easiest way to sort is with the sorted(list) function, which takes a list and returns a new list with those elements in sorted order.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ functions.html
Built-in Functions โ€” Python 3.14.3 documentation
February 27, 2026 - The sort algorithm uses only < comparisons between items. While defining an __lt__() method will suffice for sorting, PEP 8 recommends that all six rich comparisons be implemented.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-pandas-dataframe-sort_index
Pandas dataframe.sort_index() - GeeksforGeeks
Pandas sort_index() function sorts a DataFrame by its index labels (row labels) or column labels. This method allows us to rearrange the data based on the axis labels, without changing the data itself.
Published ย  December 23, 2024
๐ŸŒ
Real Python
realpython.com โ€บ python-sort
How to Use sorted() and .sort() in Python โ€“ Real Python
February 24, 2025 - Just like before, you can use sorted() to iterate through each element of the iterable you pass in. In a string, each element means each character, including spaces. Note: Python sorts strings lexicographically by comparing Unicode code points of the individual characters from left to right.
๐ŸŒ
Real Python
realpython.com โ€บ pandas-sort-python
pandas Sort: Your Guide to Sorting Data in Python โ€“ Real Python
June 13, 2023 - Learning pandas sort methods is a great way to start with or practice doing basic data analysis using Python. Most commonly, data analysis is done with spreadsheets, SQL, or pandas. One of the great things about using pandas is that it can handle a large amount of data and offers highly performant data manipulation capabilities. In this tutorial, youโ€™ll learn how to use .sort_values() and .sort_index(), which will enable you to sort data efficiently in a DataFrame.
๐ŸŒ
Medium
medium.com โ€บ @whyamit404 โ€บ understanding-sort-index-in-pandas-c1e893bd0873
Understanding sort_index() in Pandas | by whyamit404 | Medium
February 26, 2025 - True sorts the DataFrame in place, meaning it updates your original data without creating a new one. If you donโ€™t want to overwrite your DataFrame, leave this as False. ... import pandas as pd # Creating a simple DataFrame with unordered index data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 22]} df = pd.DataFrame(data, index=[3, 1, 2]) print("Original DataFrame:") print(df) # Sorting the DataFrame by index in ascending order sorted_df = df.sort_index() print("\nSorted DataFrame (Ascending Order):") print(sorted_df)
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_list_index.asp
Python List index() Method
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
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ datastructures.html
5. Data Structures โ€” Python 3.14.3 documentation
The returned index is computed relative to the beginning of the full sequence rather than the start argument. ... Return the number of times value appears in the list. ... Sort the items of the list in place (the arguments can be used for sort ...
๐ŸŒ
All About AI-ML
indhumathychelliah.com โ€บ 2020 โ€บ 09 โ€บ 29 โ€บ sorting-a-python-pandas-dataframes-by-index-and-value
Sorting a Python Pandas DataFrames by Index and Value โ€“ All About AI-ML
January 2, 2022 - The key function (str.lower()) is applied to all values in โ€œSkillโ€ column and then sorted. If containing the same values, sorted based on the row index. If the key function is not called on โ€œSkillโ€ column, upper case letters will be sorted first.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ python-pandas-sort-index-values-and-also-return-the-indices-that-would-sort-the-index
Python Pandas - Sort index values and also return the indices that would sort the index
October 14, 2021 - To sort index values and also return the indices that would sort the index, use the index.sort_values(). The return_indexer parameter is set to be True. At first, import the required librari
๐ŸŒ
Jinja
jinja.palletsprojects.com โ€บ en โ€บ stable โ€บ templates
Template Designer Documentation โ€” Jinja Documentation (3.1.x)
<div class="columnwrapper"> {%- for column in items|slice(3) %} <ul class="column-{{ loop.index }}"> {%- for item in column %} <li>{{ item }}</li> {%- endfor %} </ul> {%- endfor %} </div> If you pass it a second argument itโ€™s used to fill missing values on the last iteration. jinja-filters.sort(value: 't.Iterable[V]', reverse: bool = False, case_sensitive: bool = False, attribute: str | int | NoneType = None) โ†’ 't.List[V]'ยถ ยท Sort an iterable using Pythonโ€™s sorted().