Python sorted() function
Published February 17, 2022Python's sorted() method outputs a sorted list from an iterable object. The iterable object can be a tuple or a list. This method always outputs a sorted list or turple without interfering with the original sequence
Syntax of the sorted()
The sorted() method is written as follows
sorted(iterable, key, reverse) |
The sorted() function supports three parameters:
Iterable: An iterable is a sequence or collection that has to be sorted.
Key(optional): A key or basis for sort comparison.
Reverse(optional) : If true, the iterable would be sorted the reverse way, by default, false.
Example
a = [1,2,3,4,5,6,7,8] |
Output
The Returned Sorted List: After Reverse sort : |
Article Contributed By :
|
|
|
|
213 Views |