Reverse a List
Reverse a List
Tags: Data Structures Basics
Credit: CodingChallenge
Difficulty: Beginner
Type: Text
Category: Practice
Time Allowed: 5 s
Description:
Write a function that takes a list and returns a new list with the elements in reverse order. This problem is designed to help you practice working with lists and reversing sequences
. The function should accept one parameter and return the reversed list.
Constraints:
- The input will be a
list
of elements. - The list can be empty, in which case the returned list should also be empty.
- The function should
return
alist
with the elements in reverse order.
Example:
- Input:
[1, 2, 3, 4, 5]
- Output:
[5, 4, 3, 2, 1]
Test Case | Input | Expected Output |
---|---|---|
1 | [] | [] |
2 | [1, 2, 3, 4, 5] | [5, 4, 3, 2, 1] |
3 | ["a", "b", "c"] | ["c", "b", "a"] |
4 | [True, False, True] | [True, False, True] |
5 | [[1,2], [3,4], [5,6]] | [[5,6], [3,4], [1,2]] |
6 | [42] | [42] |
Leave a Comment
Please login to leave a comment.