Programming Examples

Python program that input a list, replace it twice and then prints the sorted list in ascending and descending order


write  a program that input a list, replace it twice and then prints the sorted list in ascending and descending order.

Solution

val=eval(input("Enter a list:"))
print("Original List :",val)
val=val*2
print("Replaced List :",val)
val.sort()
print("Sorted in ascending order :",val)
val.sort(reverse=True)
print("Sorted in Descending order :",val)
Output

Enter a list:[4,5,6,6,75,5]

Original List : [4, 5, 6, 6, 75, 5]

Replaced List : [4, 5, 6, 6, 75, 5, 4, 5, 6, 6, 75, 5]

Sorted in ascending order : [4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 75, 75]

Sorted in Descending order : [75, 75, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4]

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz