Python Practice › List Programs › Program 13
Reverse a list with a while loop
Write a Python program to reverse a list using a while loop.
Input
[1, 2, 3, 4, 5]
Output
[5, 4, 3, 2, 1]
Approach
- Walk an index from the last position down to 0.
Solution
numbers = [1, 2, 3, 4, 5]result = []i = len(numbers) - 1while i >= 0: result.append(numbers[i]) i -= 1print(result)Output
[5, 4, 3, 2, 1]
Learn the concept
New to this topic? Read the lesson, then come back.