Python Practice › Loop Programs › Program 87

Copy and sort descending

EasyLoop Programs · 87 of 90

Write a Python program to copy elements from one list into an empty list and print them in descending order.

Advertisement
Input
[2, 5, 8, 0, 1, 4]
Output
[8, 5, 4, 2, 1, 0]

Approach

  1. Copy with a loop, then sort with reverse=True.

Solution

Python
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.

More loop programs

← All 90 Loop Programs

Leave a Comment