write a program that inputs a list , replicate
it twice and than print sorted list in ascending
and descending order
Answers
Answer:
1) Python Sort List
The sort() method is used to sort the elements in a specific order i.e. Ascending or Descending.
If you want to sort the elements in Ascending order, then you can use the following syntax.
list.sort()
If you want to sort the elements in Descending order, then you can use the following syntax.
list.sort(reverse=True)
Example:
Input:
Students = ['Harsh', 'Andrew', 'Danny']
Students.sort()
print(Students)
Output:
[‘Andrew’, ‘Danny’, ‘Harsh’]
Now let’s see, How to sort the list in a Descending Order.
Input:
Students = ['Harsh', 'Andrew', 'Danny']
Students.sort()
print(Students)
Output:
[‘Andrew’, ‘Danny’, ‘Harsh’]
Thus sort() method is used to arrange a list in either Ascending or Descending order. One more important thing to remember here is that sort() method changes the order of the list permanently. If you want to change the order of the list temporarily, then you need to use sorted() function.
In this tutorial, we will explore some of the Advanced concepts in Python list.
The concepts in Python Advanced list includes Python Sort Method, Sorted function, Python Reverse List, Python Index Method, Copying a List, Python Join Function, Sum Function, Removing duplicates from the List, Python List Comprehension, etc.
Answer:
come on zoom
I'd:-9103584206
psswd:-999