reversed()
reversed(seq) reverse iterator · Updated March 13, 2026 · Built-in Functions The reversed() function takes a sequence or object supporting __reversed__ and returns a reverse iterator. It works on lists, tuples, strings, ranges, and any custom object that implements __reversed__ or both __len__ and __getitem__. Unlike slicing with [::-1], reversed() returns a lazy iterator that generates elements on demand, which is more memory-efficient for large sequences.
Syntax
reversed(seq)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
seq | sequence or iterable | — | A sequence (list, tuple, string, range) or any object with __reversed__ method |
Returns: A reverse iterator that yields elements from the sequence in reverse order. Convert to a list or tuple to materialize all values.
Examples
Basic usage with a list
The most common use case is reversing a list:
numbers = [1, 2, 3, 4, 5]
for num in reversed(numbers):
print(num)
# 5
# 4
# 3
# 2
# 1
Reversing a string
Strings are sequences, so reversed() works on them too:
text = "hello"
reversed_text = ''.join(reversed(text))
print(reversed_text)
# olleh
Converting to a list
Since reversed() returns an iterator, convert to a list if you need a list:
numbers = [1, 2, 3]
reversed_list = list(reversed(numbers))
print(reversed_list)
# [3, 2, 1]
Using with range
Works with range objects for numeric sequences:
for i in reversed(range(5)):
print(i)
# 4
# 3
# 2
# 1
# 0
Common Patterns
Processing items in reverse order
When you need to process list items from end to beginning:
tasks = ["wake up", "brush teeth", "eat breakfast", "go to work"]
for task in reversed(tasks):
print(f"Undoing: {task}")
# Undoing: go to work
# Undoing: eat breakfast
# Undoing: brush teeth
# Undoing: wake up
Building a reversed copy
Create a new list in reverse order without modifying the original:
original = [1, 2, 3, 4, 5]
reversed_copy = list(reversed(original))
print(original)
# [1, 2, 3, 4, 5]
print(reversed_copy)
# [5, 4, 3, 2, 1]
Using with custom objects
Objects implementing __reversed__ work automatically:
class Countdown:
def __init__(self, start):
self.start = start
def __iter__(self):
return iter(range(self.start, 0, -1))
def __reversed__(self):
return range(1, self.start + 1)
countdown = Countdown(5)
print(list(reversed(countdown)))
# [1, 2, 3, 4, 5]
Comparison with slice reversal
The slice [::-1] also reverses sequences but creates a new list immediately:
numbers = [1, 2, 3]
sliced = numbers[::-1]
print(sliced)
# [3, 2, 1]
# reversed() is more memory-efficient for large sequences
# because it yields items lazily
See Also
- built-in::sorted — return a new sorted list from the items in iterable
- built-in::enumerate — add a counter to an iterable, useful when you need indices while iterating
- built-in::range — generate a sequence of numbers, often used for reverse iteration with a step of -1