Python Practice › Loop Programs › Program 87
Copy and sort descending
Write a Python program to copy elements from one list into an empty list and print them in descending order.
Input
[2, 5, 8, 0, 1, 4]
Output
[8, 5, 4, 2, 1, 0]
Approach
- Copy with a loop, then sort with
reverse=True.
Solution
a = [2, 5, 8, 0, 1, 4]b = []for x in a: b.append(x)b.sort(reverse=True)print(b)Output
[8, 5, 4, 2, 1, 0]
Learn the concept
New to this topic? Read the lesson, then come back.