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 tuple
tu = (8,3,4,5,6)
print("Sorted tuple:", sorted(tu))



Output


Picture showing the output of Sorted method in python



Sorting The Sequence In Reverse Order




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

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



Output


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



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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250