Web Analytics

Python list.sort() Method

List Method â€ĸ Sorting

The sort() method sorts the list ascending by default. You can also make a function to decide the sorting criteria(s).

Syntax

list.sort(reverse=True|False, key=myFunc)

Parameters

Parameter Description
reverse Optional. reverse=True will sort the list descending. Default is reverse=False
key Optional. A function to specify the sorting criteria(s)

Return Value

None. The list is modified in place.

Example

Using the sort() method:

Output
Click Run to execute your code

Related Functions