Computer Science

Write a program that inputs a list, replicates it twice and then prints the sorted list in ascending and descending orders.

Python

Python List Manipulation

12 Likes

Answer

List1 = eval(input("Enter the list: "))
List2 = List1 * 2
List2.sort()
print("Sorted list in ascending order:", List2)
List2.sort(reverse=True)
print("Sorted list in descending order:", List2)

Output

Enter the list: [4, 5, 2, 9, 1, 6]
Sorted list in ascending order: [1, 1, 2, 2, 4, 4, 5, 5, 6, 6, 9, 9]
Sorted list in descending order: [9, 9, 6, 6, 5, 5, 4, 4, 2, 2, 1, 1]

Answered By

3 Likes


Related Questions