In this program, we will take a user input as a list. Sort the given list using the sort and sorted method with the help of the below-given steps.
Table of Contents
Sort and sorted method:
Method 1 : Using Sort()
Steps to solve the program
- Take a list as input.
- Sort the list using sort().
- Print the output.
#Input list
list1 = [23,11,78,45,33]
#Using sort
list1.sort()
print("By sort function: ",list1)
Output :
By sort function: [11, 23, 33, 45, 78]
Method 2 : Using sorted()
Steps to solve the program
- Take a list as input,
- Sort the list using sorted().
- Print the output.
#Input list
list1 = [23,11,78,45,33]
#using sorted
print("By sorted method: ",sorted(list1))
Output :
By sorted method: [11, 23, 33, 45, 78]
Related Articles
Python program to remove data from the list from a specific index using the pop method.
Python program to get the max, min, and sum of the list using in-built functions.
Python program to check whether a list contains a sublist.
Python program to generate all sublists with 5 or more elements in it from the given list.
Python program to find the second largest number from the list.
Python program to find the second smallest number from the list.