Editor

Reverse a List

Lists · Beginner · 45 XP · about 5 min

Write a function called reverse_list(lst) that returns a new list with elements in reverse order.

Challenge: Try to solve this without using Python's built-in reverse() method or [::-1] slicing!

Example

reverse_list([1, 2, 3, 4, 5])  # Returns [5, 4, 3, 2, 1]
reverse_list(["a", "b", "c"])  # Returns ["c", "b", "a"]
reverse_list([1])              # Returns [1]

Requirements

  • Return a new reversed list (don't modify the original)
  • Handle lists of any type
  • Handle empty lists
def reverse_list(lst):
# Your code here - try without [::-1]!
pass
# Test your function
print(reverse_list([1, 2, 3, 4, 5]))
print(reverse_list(["a", "b", "c"]))

Ready?

Accept the challenge to start writing. A small timer counts the time this page is in view.

Output appears here.