Python Reference Library →

Python reversed() Function – Reverse Iterables Easily

Let’s look at reversed() function – reverse iterables easily

  1. Notice

    reversed() returns an iterator over a reversible sequence in reverse order. It does not change the original sequence.

  2. Try

    Follow the example, change its sample, and compare what happens.

  3. Check

    Explain the result and test your understanding.

Watch how it works

Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.

Explore the idea

Follow the code and watch its state change. Guided simulation.

Code
Python
items = [3, 2, 5]
print(list(reversed(items)))
print(items)
Live state

Top-level scope

items→Object 1
Object 1 · list[3, 2, 5]
This step

reversed() returns an iterator over a reversible sequence in reverse order. It does not change the original sequence.

Picture reversed() function – reverse iterables easily

reversed() returns an iterator over a reversible sequence in reverse order. It does not change the original sequence.

Image brief

Alt text
A diagram for Python reversed() Function – Reverse Iterables Easily. Instructions: items = [3, 2, 5] print(list(reversed(items))) print(items). Displayed result: [5, 2, 3] [3, 2, 5]. The final example bindings are items --> object 1 (list). object 1: [3, 2, 5]
Image generation prompt
Create a clean educational illustration for a Python programming lesson titled "Python reversed() Function – Reverse Iterables Easily". Teaching focus: reversed() returns an iterator over a reversible sequence in reverse order. It does not change the original sequence. Depict exactly the relationships and labels in this reference diagram: EXAMPLE INSTRUCTIONS items = [3, 2, 5] print(list(reversed(items))) print(items) | v DISPLAYED RESULT [5, 2, 3] [3, 2, 5] FINAL BINDINGS items --> object 1 (list) object 1: [3, 2, 5] Use a flat vector style, generous spacing, clear arrows and legible labels, with a restrained blue/teal palette on a plain background. The diagram must explain the programming idea accurately. Do not depict variables as boxes containing copied objects when they share a reference. Avoid mascots, decorative screenshots, logos, gradients and extra text. Landscape composition, approximately 3:2, suitable for a course card. Accessible description: A diagram for Python reversed() Function – Reverse Iterables Easily. Instructions: items = [3, 2, 5] print(list(reversed(items))) print(items). Displayed result: [5, 2, 3] [3, 2, 5]. The final example bindings are items --> object 1 (list). object 1: [3, 2, 5]

Follow the execution

Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
Python
items = [3, 2, 5]
print(list(reversed(items)))
print(items)
Live state

Top-level scope

items→Object 1
Object 1 · list[3, 2, 5]
This step

The example has finished. Compare the final output with the values and references above.

Terminal
Output
[5, 2, 3]
[3, 2, 5]

What do you expect this program to print?

What does this example display?

items = [3, 2, 5]
print(list(reversed(items)))
print(items)
What does this example display?
Choose one answer. You can try again.

Answer and explanation

[5, 2, 3] [3, 2, 5]

Follow the printed values in order. The output is: [5, 2, 3] [3, 2, 5]

Which explanation matches what you learned?

Which explanation matches what you learned?
Choose one answer. You can try again.

Answer and explanation

reversed() returns an iterator over a reversible sequence in reverse order. It does not change the original sequence.

reversed() returns an iterator over a reversible sequence in reverse order. It does not change the original sequence.

More examples and reference

Python reversed() Function

The reversed() function in Python returns an iterator that accesses the given sequence in the reverse order. It is commonly used to loop through lists or other sequences from the end to the beginning.

Syntax

reversed(sequence)

Parameters:

  • sequence – A sequence that supports reverse iteration (like list, tuple, string, or a user-defined class with __reversed__()).

Returns:

  • An iterator that returns the elements in reverse order.

Example 1: Reversing a List

numbers = [1, 2, 3, 4, 5]
for num in reversed(numbers):
    print(num)
5
4
3
2
1

Example 2: Reversing a String

text = "hello"
for char in reversed(text):
    print(char)
o
l
l
e
h

Example 3: Convert Reversed Iterator to List

items = ['a', 'b', 'c']
rev_items = list(reversed(items))
print(rev_items)
['c', 'b', 'a']

Use Cases of reversed()

  • To iterate backward in loops
  • To reverse a string or list without modifying the original
  • In problems involving palindromes or reverse traversal

Important Notes

  • reversed() does not return a reversed list directly — it returns an iterator.
  • You need to convert it to list() or tuple() if you want to store or print the reversed result directly.

Common Mistakes

  • Using reversed() on non-sequence types like sets or dictionaries will raise a TypeError.
  • To reverse those, you can convert them to a list first: reversed(list(my_set))

Interview Tip

In interviews, use reversed() when you're asked to check for palindromes or reverse iteration in loops. It's cleaner and more readable than using indexes.

Summary

  • reversed() returns an iterator for reverse traversal.
  • Works with lists, tuples, strings, and custom objects with __reversed__().
  • Use list(reversed(...)) to get a reversed list.

Practice Problem

Write a program that checks if a word is a palindrome (reads the same backward).

word = input("Enter a word: ")
if list(word) == list(reversed(word)):
    print("It's a palindrome!")
else:
    print("Not a palindrome.")

What to remember

Connect what you noticed in the example with the idea below.

Remember

reversed() returns an iterator over a reversible sequence in reverse order. It does not change the original sequence.

Watch out for this idea

reversed() always modifies its source list.

This is the misconception to avoid.

Reference checks are optional and do not count toward course progress.

    Reference library →