Python sorted() function

Python sorted() function

The sorted() function returns a sorted list of the specified iterable object.

Syntax

Parameter

iterable: It is a required parameter that represents the sequence to sort, list, dictionary, tuple etc.

key: It is an optional parameter that signifies a Function to execute to decide the order. 

reverse: It represents a Boolean parameter where the ‘False’ will sort in the ascending order, whereas the ‘True’ will sort in the descending order. 

Return

This function returns a new sorted list from the items in iterable.

Example 1

Output

Example 2

Output

Example 3

Output