Articles → Python → Sorted Method In Python

Sorted Method In Python






Purpose





Example


# Sorting list
li = [2,3,1,4,5]
print("Sorted list:", sorted(li))

# Sorting tupple
tu = (8,3,4,5,6)
print("Sorted tuple:", sorted(tu))



Output


Picture showing the output of Sorted method in python

Click to Enlarge


Sorting The Sequence In Reverse Order




# Sorting list
li = [2,3,1,4,5]
print("Sorted list:", sorted(li, reverse = True))

# Sorting tupple
tu = (8,3,4,5,6)
print("Sorted tuple:", sorted(tu, reverse = True))




Picture showing the output of Sorted method in python for sorting in  reverse order

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, May 8, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250