---
title: "Python List Reversal: Built-in and Custom Techniques Explained"
description: "The content discusses two methods in Python for reversing lists: a custom-built function and the built-in reversed() method."
url: https://srinimf.com/2023/11/14/how-to-reverse-list-simplified-python-function/
date: 2023-11-14
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2023/07/pexels-photo-4308102.jpeg?fit=1880%2C1253&ssl=1
categories: ["Python"]
tags: ["Reverse a List in Python"]
type: post
lang: en
---

# Python List Reversal: Built-in and Custom Techniques Explained

Here is a Python program that shows reversing a list: built-in and custom methods.

Related[Append() vs Extend(): A Detailed Comparison for Python Lists](https://srinimf.com/2024/09/12/append-vs-extend-a-detailed-comparison-for-python-lists/)

![Reverse a list in Python](https://i0.wp.com/srinimf.com/wp-content/uploads/2023/07/pexels-photo-4792319.jpeg?resize=1880%2C1255&ssl=1)*Photo by Anete Lusina on Pexels.com*

Related[Pass by Value and Pass by Reference in Python](https://srinimf.com/2022/05/23/python-pass-by-value-vs-pass-by-reference-simple-example/)

Table of contents

1. [CUSTOM Method](https://srinimf.com/2023/11/14/how-to-reverse-list-simplified-python-function/#custom-method)
2. [Built-in method](https://srinimf.com/2023/11/14/how-to-reverse-list-simplified-python-function/#built-in-method)

## CUSTOM Method

Here’s a class called RevIter that takes a list and reverses each item using the pop method. The init method initializes the argument, the iter method iterates through the list, and the next method processes each item. The pop method selects the last item to process first.

```
class RevIter:
    def __init__(self, iterable):
        self.iterable = iterable  # Stores the list
    def __iter__(self):
        return self
    def __next__(self):
        try:
            return self.iterable.pop()  # Removes and returns the last element
        except IndexError:
            raise StopIteration
            
# Usage of the function
a=[]
for i in RevIter([1, 2, 3, 4, 5]):
    a.append(i)
  
print(a)  # Output: [5, 4, 3, 2, 1]
```

Output

```
[5, 4, 3, 2, 1]
```

## Built-in method

Here I used a built-in method called **reversed**. To store the output, I have assigned the variable reversed_list. Then, using the for loop, read each item and write it to the output.

```
my_list=[1,2,3,4]
reversed_list = reversed(my_list)
output=[]
for item in reversed_list:
    output.append(item)
    
print(output)
```

Output

```
[4, 3, 2, 1]


** Process exited - Return Code: 0 **
Press Enter to exit terminal
```

Conclusion

- You can reverse a list using a custom function or the built-in reversed() method.
- The custom function uses the pop() method to reverse.
- The built-in method(reversed) returns an iterator that iterates over the list in reverse order.
- Both methods produce the same outcome.

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2023%2F11%2F14%2Fhow-to-reverse-list-simplified-python-function%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2023%2F07%2Fpexels-photo-4308102.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=Python%20List%20Reversal%3A%20Built-in%20and%20Custom%20Techniques%20Explained)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2023/11/14/how-to-reverse-list-simplified-python-function/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2023/11/14/how-to-reverse-list-simplified-python-function/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2023/11/14/how-to-reverse-list-simplified-python-function/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2023/11/14/how-to-reverse-list-simplified-python-function/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20Python%20List%20Reversal%3A%20Built-in%20and%20Custom%20Techniques%20Explained&body=https%3A%2F%2Fsrinimf.com%2F2023%2F11%2F14%2Fhow-to-reverse-list-simplified-python-function%2F&share=email)
-

### Like this:

Like Loading…
