Python reverse list: The Complete Guide

Reversing a list is a standard operation in Python programming. For example, imagine you had the sorted list of the employee names that your code displays in alphabetical (A-Z) order. Some of your users would like to view the employee list so that the names are in reverse alphabetical order. How will you flip the order of this existing list on its head? 

In this article, you’ll see three different ways to achieve this result in “plain vanilla” Python, meaning without the use of any third-party Python libraries:

  1. Reversing the list in place with a Python list.reverse() method.
  2. Using the “[::-1]” list slicing technique to create a reversed copy.
  3. Creating a reverse iterator with a reversed() built-in function.

Python reverse list

To reverse a list in Python, use the list.reverse() method. The reverse() is a built-in Python function that reverses the sorting order of the items. The reverse() function takes no parameters and doesn’t return any value. It only reverses the elements and updates the list.

List reverse() reverses objects of the list in place.

Let’s start with the list.reverse() function in Python.


The syntax of the Python list reverse() method is the following.


A simple example is the following.


GoT = ['Jon', 'Tyrion', 'Daenerys']
print (GoT)

See the output.

Python List Reverse Example | reverse() Tutorial

One thing to remember is that it does not do any ascending or descending order on the list.

It just merely reverses the list regardless of whether the input string is already ordered or not.

The list reverse() method modifies the sequence in place for space economy when reversing an extensive sequence. If we want to remind employees that it operates by side effect, it does not return the reversed sequence. (Source: Python 3 Docs).

The in-place reversal has some benefits and some downsides. On the plus side, it’s a fast operation—shuffling the list elements around doesn’t require much extra memory, as we’re not creating the full copy of the list.

However, reversing the list in place overwrites the original sort order. This could be a potential downside. (Of course, you could reverse the same list again to restore the original order.)

From the code readability standpoint, I like this approach.

The syntax is clear and easy to understand, even for the developers new to Python or someone from another language background.

List sort() and reverse() combined

Let’s take a scenario where first we are sorting the list based on the criteria of length of string item and then reverse that order in the list.


def criteria(item):
    return len(item)
GoT2 = ['Jon', 'Tyrion', 'Daenerys']
GoT2.sort(reverse=True, key=criteria)
print (GoT2)
print (GoT2)

So, in the above example, we are descending the list based on the length of the string item and then reverse that item on the list.

So the output is the following.

List sort() and reverse() combined example

If you want to learn how to sort a list in Python, check out my list sort() article.

Accessing Individual Elements in Reversed Order

Let’s access all the elements in reverse order.


GoT1 = ['Jon', 'Tyrion', 'Daenerys']
for item in GoT1:
    print (item)

First, we reverse the list’s order and then print items one by one.

Python list reverse() Tutorial

Reverse a Python List Using Slicing Operator

PythPython’st objects have an exciting feature called slicing.

You can view it as an extension of the square-brackets indexing syntax.

It includes the particular case where slicing a list with. “[::-1]” “r”duces the reversed copy.

Let’Let’s a Python list slice() method to reverse the list.


st = ['David', 'Millie', 'Winona']
print('Original List:', st)

# Reversing a list	
#Syntax: reversed_list = os[start:stop:step] 
reversed_list = st[::-1]

# updated list
print('Updated List:', reversed_list)

 See the output.

➜  pyt python3
Original List: ['David', 'Millie', 'Winona']
Updated List: ['Winona', 'Millie', 'David']
➜  pyt

Reversing the list this way takes up more memory than an in-place reversal because it creates a (shallow) copy of the list, and creating the copy requires allocating enough space to hold all of the existing items.

Note that this only creates a “sha”low” co”y where the container is duplicated, but not the individual list items.

Instead of duplicating the list items themselves, references to the original elements are reused in the new copy of the container.

If the items are mutable, modifying an item in the original list will also be reflected in the copy.

The biggest downside to reversing the list with a slicing syntax is that it uses a more advanced Python feature that some people would say is “arc”ne.”

I “on’don’tme them—list slicing is fast and a little challenging to understand the first time you encounter its quirky syntax.

When I’m I’mding Python code that uses list slicing, I often have to slow down and concentrate to “men”ally parse” th” statement to make sure I understand whatwhat’sng on.

My biggest gripe here is that the “[::-1]” “l”cing syntax does not communicate enough that it creates a reversed copy of the original list.

Using PythPython’scing feature to reverse a list is a decent solution, but it can be challenging to read uninitiated.

Creating a Reverse Iterator With the reversed() Function

Reversing a list using reverse iteration with the reversed() is another option. It neither reverses a list in place nor does it create a full copy.

Instead, we get a reverse iterator we can use to cycle through the list elements in reverse order.

See the following code.


st = ['David', 'Millie', 'Winona']
print('Original List:', st)

for item in reversed(st):

See the output.

➜  pyt python3
Original List: ['David', 'Millie', 'Winona']
➜  pyt

ThatThat’sfor this tutorial.

Related Posts

Python list extend()

Python list pop()

Python list sort()

Python list index()

Python list copy()

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.