Python reversed() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Built-in type

Definition

In Python, reversed(seq) returns an iterator that yields the items of a sequence from last to first. It does not copy the data and does not change the original. Wrap it in list() or "".join() to get a reversed copy.

It works with anything that has a __reversed__() method or supports len() and indexing: lists, tuples, strings, ranges, and, since Python 3.8, dicts and their views. Like every iterator, the result can be used only once.

reversed is a built-in type (a class) that you call like a function: each call creates a new reversed object. Like every built-in, it lives in the builtins module and is always available without an import.

Syntax

Usually used directly in a for loop.

python
for item in reversed(sequence):
    ...
CallWhat it does
list(reversed([1, 2, 3]))Returns [3, 2, 1].
"".join(reversed("abc"))Returns "cba".
reversed(range(5))Counts 4, 3, 2, 1, 0.
list(reversed(d))Dict keys, last inserted first (3.8+).

seq[::-1] makes a reversed copy in one step; reversed() avoids the copy, which matters for big lists.

Library declarations
python
reversed(seq, /)
# class reversed: returns a reverse iterator

Parameters

ParameterDescription
seqRequired. A sequence (has __len__() and __getitem__()) or an object with __reversed__().

Return Value

Return ValueDescription
iteratorA reverse iterator. Print list(...) of it, not the iterator itself.

Python Examples

Example 1 — A Reverse Iterator Is Used Once

Reverse a list and a string, and see that the iterator empties after one pass.

python
letters = ["a", "b", "c"]
backwards = reversed(letters)

print(type(backwards).__name__)
print(list(backwards))
print(list(backwards))
print("".join(reversed("stressed")))
print(letters)

How It Works

  1. An iterator, not a list. The type name shows list_reverseiterator; nothing is copied yet.
  2. Consumed once. The first list() takes all items, so the second gets none.
  3. Strings. Joining the reversed characters of "stressed" spells "desserts".
  4. Original intact. letters is unchanged, unlike letters.reverse().

Example 2 — Loop Backwards with Numbers

Count down with a reversed range and number the steps of a list from the end.

python
for i in reversed(range(1, 4)):
    print("T-minus", i)

steps = ["mix", "bake", "cool"]
for number, step in enumerate(reversed(steps), 1):
    print(number, step)
print(list(reversed((1, 2, 3))))

How It Works

  1. Reversed range. reversed(range(1, 4)) yields 3, 2, 1, often clearer than a negative step.
  2. Combine with enumerate. enumerate() numbers the reversed items starting at 1.
  3. Lazy chain. Neither call builds a list; items flow one at a time.
  4. Tuples too. Any sequence works, and list() collects the result.

Example 3 — Reverse Dicts, Custom Classes, and Sets

Reverse a dict (Python 3.8+), give a class its own __reversed__(), and try a set.

python
class Playlist:
    def __init__(self, songs):
        self.songs = list(songs)

    def __reversed__(self):
        return iter(self.songs[::-1])


ranks = {"gold": 1, "silver": 2, "bronze": 3}
print(list(reversed(ranks)))
print(list(reversed(Playlist(["intro", "verse", "outro"]))))

try:
    reversed({1, 2, 3})
except TypeError:
    print("sets have no order, so reversed() fails")

How It Works

  1. Dicts since 3.8. reversed(ranks) yields keys from the last inserted to the first.
  2. __reversed__ hook. reversed() calls Playlist.__reversed__, which returns an iterator over a reversed copy.
  3. Only ordered data. A set has no defined order, so it raises TypeError.
  4. Convert first. reversed(sorted(my_set)) works when you need a descending walk.

Frequently Asked Questions

Use list(reversed(items)) or items[::-1] for a new list, or items.reverse() to reverse it in place.
reversed() returns a lazy iterator. Wrap it: print(list(reversed(x))).
Use "".join(reversed(text)) or the slice text[::-1].
Yes, on Python 3.8 and later. It yields the keys from the most recently inserted to the oldest.
They have no defined order or length. Convert to a list first: reversed(list(gen)).

Next: round()

Round a number to a given number of decimals.

round() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful