Python set sorted method

Python set sorted function is one of the set methods 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

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

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

program Example 2

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

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

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.