Reverse a List in Python: reverse() vs. reversed()

Python provides two common ways to reverse a list:

  1. reverse() method (modifies the list in-place)
  2. reversed() function (returns a reversed iterator)

Each has its own advantages depending on the use case.


1. reverse() Method (In-Place Reversal)

  • Works only on lists.
  • Modifies the original list directly (in-place).
  • More memory-efficient since it doesn’t create a new list.

Example:

my_list = [1, 2, 3, 4, 5]
my_list.reverse()  
print(my_list)  # Output: [5, 4, 3, 2, 1]

✔️ Use reverse() when you want to modify a list without creating a new list.


2. reversed() Function (Returns an Iterator)

  • Works with any iterable (lists, tuples, strings, etc.).
  • Returns a reverse iterator, which can be converted to a list or used in a loop.
  • Does not modify the original iterable.

Example:

my_list = [1, 2, 3, 4, 5]
reversed_list = list(reversed(my_list))  
print(reversed_list)  # Output: [5, 4, 3, 2, 1]

✔️ Use reversed() when you need a new reversed list while keeping the original intact.


Choosing Between reverse() and reversed()

Featurereverse()reversed()
Modifies Original List?✅ Yes (in-place)❌ No (creates new iterator)
Return TypeNone (modifies list)Iterator (convert to list if needed)
Works on Other Iterables?❌ No (only lists)✅ Yes (tuples, strings, etc.)
Memory UsageEfficient (no copy created)Less efficient (creates a new object)

✔️ Use reverse() when you need an in-place modification of a list.
✔️ Use reversed() when you need to reverse any iterable without modifying the original data.


Summary

Both reverse() and reversed() provide flexibility:

  • reverse() is best for modifying a list directly.
  • reversed() is best for working with any iterable while preserving the original.

Choose based on whether you need in-place modification or a new reversed version. 🚀

Hello, I’m Anuj. I make and teach software.

My website is free of advertisements, affiliate links, tracking or analytics, sponsored posts, and paywalls.
Follow me on LinkedIn, X (twitter) to get timely updates when I post new articles.
My students are the reason this website exists. ❤️

Feedback Display