CKTIS / Python
reversed()
Returns an iterator over a reversible object in reverse order.
Version: Python 3.14; repository image, production runtime not attested
Syntax
reversed(sequence, /)Returns an iterator over a reversible object in reverse order.
Consuming the built-in list reverse iterator leaves the source list intact. A consumed iterator yields no more values.
This requests __reversed__ or falls back to length and integer indexing on a sequence. Iteration returns 8, 4 and 2 without changing the source list. The same iterator then has nothing left. An arbitrary forward-only iterator need not support reversal.
a = [2, 4, 8]
it = reversed(a)
assert list(it) == [8, 4, 2] and a == [2, 4, 8] and list(it) == []
Examples
items = [2, 4, 8]
it = reversed(items)
print(list(it))
print(items, list(it))
Result
[8, 4, 2] [2, 4, 8] []
This requests `__reversed__` or falls back to length and integer indexing on a sequence. Iteration returns 8, 4 and 2 without changing the source list. The same iterator then has nothing left. An arbitrary forward-only iterator need not support reversal.