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



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))





Click to Enlarge


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250