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 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad