Python set sorted method

Python set sorted function is one of the set method used to sort the given set items in ascending order or Descending order. The syntax behind this set sort function is:

sorted(set_Name, reverse = True

Python set sorted function example 1

sortFruitSet = {'mango', 'kiwi', 'apple', 'orange', 'banana'}
print("\nOld Set Items = ", sortFruitSet)

# Python Set sorting
print("Sorted List from Set = ", sorted(sortFruitSet))
Old Set Items = {'apple', 'kiwi', 'orange', 'mango', 'banana'}
Sorted List from Set = ['apple', 'banana', 'kiwi', 'mango', 'orange']

Python set sorted function example 2

sortFruitSet = {'mango', 'kiwi', 'apple', 'orange', 'banana'}
print("\nOld Set Items = ", sortFruitSet)

# Python Set sorting
print("Sorted List from Set = ", sorted(sortFruitSet))
Python set sort method 2