4Geeks chosen to deliver AI education in the Bahamas alongside Harvard, Oxford, and Columbia.See more

How to Reverse a List in Python?

By 4Geeks

Reverse a list in place or as a copy, loop backwards, reverse strings and sentences and avoid the reverse() returns None trap.

6 min readLast updated
Reverse a list in Python icon

How do you reverse a list in Python?

Short answer: call nums.reverse() to reverse the list itself, or use nums[::-1] to get a reversed copy and keep the original. To loop backwards without making a copy, use reversed(nums).

python
nums = [1, 2, 3, 4, 5]
 
nums.reverse()
print(nums)          # [5, 4, 3, 2, 1]
 
print(nums[::-1])    # [1, 2, 3, 4, 5]  a new list

reverse() returns None, so never write nums = nums.reverse(). Strings have no reverse(), but "hello"[::-1] returns 'olleh'.

reverse() changes the list itself, [::-1] returns a new reversed list and also works with strings.

Every way to reverse in Python

What you wantCodeChanges the originalReturns
Reverse the list itselfnums.reverse()YesNone
A reversed copynums[::-1]NoA new list
Loop backwardsfor n in reversed(nums):NoAn iterator
A reversed copy from the iteratorlist(reversed(nums))NoA new list
Sort from largest to smallestsorted(nums, reverse=True)NoA new sorted list
Reverse a string"hello"[::-1] or "".join(reversed("hello"))No (strings can't change)'olleh'
Reverse the words of a sentence" ".join(reversed(text.split()))No'Python love I'
Reverse a tuple(1, 2, 3)[::-1]No(3, 2, 1)
Count downrange(5, 0, -1)—5, 4, 3, 2, 1

Reverse a list in place with reverse()

reverse() flips the order of the list you call it on. It doesn't create a new list and it returns None:

python
nums = [1, 2, 3, 4, 5]
result = nums.reverse()
 
print(nums)     # [5, 4, 3, 2, 1]
print(result)   # None

Every variable that points to that list sees the change:

python
a = [1, 2, 3]
b = a
a.reverse()
print(b)        # [3, 2, 1]

Use it when you don't need the original order any more. It is also the fastest option: in a test with a million numbers, reverse() took about 0.5 ms and [::-1] about 4 ms.

Career · AI Engineering

You already handle Python lists, now build with AI

From zero to junior AI Engineer: Python, data, AI agents and RAG with mentors and real projects.

Get a reversed copy with slicing [::-1]

The slice [start:stop:step] with a step of -1 walks the list from the end to the start and builds a new list:

python
nums = [1, 2, 3, 4, 5]
backwards = nums[::-1]
 
print(backwards)   # [5, 4, 3, 2, 1]
print(nums)        # [1, 2, 3, 4, 5]  unchanged

With other steps you can also skip items: [1, 2, 3, 4, 5][::-2] returns [5, 3, 1].

Loop backwards with reversed()

reversed() returns an iterator that gives the items from the last to the first, without copying the list. It's the best choice for a for loop:

python
for fruit in reversed(["apple", "banana", "cherry"]):
    print(fruit)
# cherry
# banana
# apple

The iterator is not a list, so len() and indexes don't work on it. Wrap it in list() when you need a list: list(reversed(nums)).

Reverse vs sort in reverse order

Reversing flips the current order. Sorting with reverse=True orders the items from largest to smallest:

python
nums = [3, 1, 2]
 
print(nums[::-1])                    # [2, 1, 3]  just flipped
print(sorted(nums, reverse=True))    # [3, 2, 1]  sorted, descending

nums.sort(reverse=True) does the same but changes the list.

Reverse a string in Python

Strings can't be changed, so they have no reverse() method. Use slicing, or join() with reversed():

python
text = "hello"
 
print(text[::-1])                  # olleh
print("".join(reversed(text)))     # olleh

To reverse the order of the words instead of the letters, split the sentence first:

python
sentence = "I love Python"
print(" ".join(reversed(sentence.split())))   # Python love I

A common use is checking palindromes:

python
word = "racecar"
print(word == word[::-1])   # True

Reverse nested lists, tuples and NumPy arrays

python
nested = [[1, 2], [3, 4]]
print(nested[::-1])                  # [[3, 4], [1, 2]]  order of the lists
print([row[::-1] for row in nested]) # [[2, 1], [4, 3]]  each list inside
 
print((1, 2, 3)[::-1])               # (3, 2, 1)
 
import numpy as np
print(np.flip(np.array([1, 2, 3])))  # [3 2 1]

Use AI to reverse and reorder your data

An assistant like ChatGPT, Claude or GitHub Copilot can pick the right method for your case and explain a strange result. These three prompts are ready to copy.

1. Choose a method

In Python I have this list: [paste a short example].
I need it [reversed / sorted from largest to smallest / reversed without changing the original].
Show me the best way and explain why.

2. Explain a result

This Python code: [paste your code]
prints [what you see] and I expected [what you expected].
Explain why and how to fix it.

3. Reverse text

I need to reverse [the letters / the words / each word] of this text in Python: "[your text]".
Show me the code and the result.

Run the code with a short example you can check by eye.

Learn with a mentor

From reversing lists to AI applications

In the 4Geeks AI Engineering career program you start with no experience and finish with AI agents and RAG systems in your portfolio.

Common problems when reversing in Python

What you seeWhy it happensFix
The list is None after nums = nums.reverse()reverse() changes the list and returns NoneWrite nums.reverse() on its own line, or nums = nums[::-1]
AttributeError: 'str' object has no attribute 'reverse'Strings can't be changed in placetext[::-1]
<list_reverseiterator object at 0x...> when you printreversed() returns an iteratorlist(reversed(nums))
TypeError: object of type 'list_reverseiterator' has no len()Iterators don't have a lengthUse len(nums), or convert with list()
Another variable also changedreverse() changes the list every variable points toUse nums[::-1] to keep the original
The list is sorted, not reversedsort(reverse=True) sorts in descending orderUse reverse() or [::-1] to only flip it
Emoji or accents look broken when reversedSome characters are made of several code pointsReverse with a library that handles graphemes, such as regex
Free download

Reversing in Python in a 2-page cheat sheet

reverse(), [::-1], reversed(), reverse vs sort, strings and sentences, nested lists, tuples and NumPy, common errors and prompts for ChatGPT, Claude or Copilot. Free, in PDF.

How to reverse a list in Python cheat sheet

2 pages · PDF · 4Geeks

  • Every way to reverse lists and strings in one table
  • When the original list changes and when it doesn't
  • Common errors and prompts to solve them with AI

Get it free

Your PDF right away

Frequently asked questions about reversing lists in Python

Want to go from your first Python lists to building AI applications, with real projects and mentors?

See the AI Engineering program