🚀 Supercharge your YouTube channel's growth with AI.
Try YTGrowAI FreeReverse an Array in Python – 10 Examples

Reversing an array is one of the most fundamental operations in Python, yet Python does not have a single array type — it has lists, the array module, and NumPy. Each behaves differently when reversed. This guide covers every method with up-to-date examples so you can pick the right tool for your situation.
TLDR: Use list slicing [::-1] for a quick reversed copy of a Python list. Use arr.reverse() for in-place reversal of a list. For NumPy arrays, prefer np.flip() or arr[::-1] — both are fast and return new arrays. The array module also supports .reverse() but only works on 1D data.
Output:
This is the most Pythonic one-liner. It works on any sequence (list, tuple, string).
Output:
Important: This mutates the original list. Use it when you don’t need the original order.
Output:
This is memory-efficient for large lists since it doesn’t create a full copy upfront.
Output:
Output:
Output:
Output:
Output:
Slicing returns a view when possible (no copy is made), making it both fast and memory-efficient.
Output:
For a pure Python nested list, you need nested comprehension to reverse both dimensions:
Reverse a List in Python
Lists are Python’s default sequence type. They support both in-place and copy-based reversal.1. List Slicing
Slicing with a step of -1 creates a reversed copy without modifying the original.
arr = [11, 22, 33, 44, 55]
print("Original:", arr)
reversed_arr = arr[::-1]
print("Reversed:", reversed_arr)
print("Original unchanged:", arr)
Original: [11, 22, 33, 44, 55]
Reversed: [55, 44, 33, 22, 11]
Original unchanged: [11, 22, 33, 44, 55]
2. The list.reverse() Method
The reverse() method reverses the list in place. It modifies the original and returns None.
arr = [11, 22, 33, 44, 55]
arr.reverse()
print("Reversed in place:", arr)
Reversed in place: [55, 44, 33, 22, 11]
3. The reversed() Built-in Function
reversed() returns an iterator that yields items in reverse order. Wrap it with list() to get a new list.
arr = [12, 34, 56, 78]
result = list(reversed(arr))
print("Reversed:", result)
print("Original:", arr)
Reversed: [78, 56, 34, 12]
Original: [12, 34, 56, 78]
Reverse a Python array Module
The array module provides fixed-type arrays (‘i’ for integers, ‘f’ for floats). Unlike NumPy, it’s part of the standard library with no extra install.1. The array.reverse() Method
The array module’s reverse() works the same way as list’s — in place, no return value.
import array
arr = array.array(‘i’, [2, 4, 6, 8, 10, 12])
print("Before:", arr)
arr.reverse()
print("After:", arr)
Before: array(‘i’, [2, 4, 6, 8, 10, 12])
After: array(‘i’, [12, 10, 8, 6, 4, 2])
2. The reversed() Built-in
You can also use reversed() with an array, then reconstruct an array from it.
import array
arr = array.array(‘i’, [10, 20, 30, 40])
reversed_arr = array.array(‘i’, reversed(arr))
print("Original:", arr)
print("Reversed:", reversed_arr)
Original: array(‘i’, [10, 20, 30, 40])
Reversed: array(‘i’, [40, 30, 20, 10])
Reverse a NumPy Array in Python
NumPy arrays are the go-to choice for numerical computing in Python. They support fast vectorized reversal along one or all axes.1. Using np.flip()
np.flip() reverses along all axes by default and returns a new array.
import numpy as np
arr = np.array([‘A’, ‘s’, ‘k’, ‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’])
print("Original:", arr)
reversed_arr = np.flip(arr)
print("Reversed:", reversed_arr)
Original: [‘A’ ‘s’ ‘k’ ‘P’ ‘y’ ‘t’ ‘h’ ‘o’ ‘n’]
Reversed: [‘n’ ‘o’ ‘h’ ‘t’ ‘y’ ‘P’ ‘k’ ‘s’ ‘A’]
2. Using np.flipud()
np.flipud() flips the array vertically (up-down). For a 1D array this behaves identically to np.flip(), but for 2D arrays it only reverses rows.
import numpy as np
arr = np.array([‘A’, ‘s’, ‘k’, ‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’])
print("Original:", arr)
print("Flipped up-down:", np.flipud(arr))
Original: [‘A’ ‘s’ ‘k’ ‘P’ ‘y’ ‘t’ ‘h’ ‘o’ ‘n’]
Flipped up-down: [‘n’ ‘o’ ‘h’ ‘t’ ‘y’ ‘P’ ‘k’ ‘s’ ‘A’]
3. Slicing with [::-1]
NumPy supports the same slice notation as Python lists.
import numpy as np
arr = np.array([1, 3, 5, 7, 9])
print("Original:", arr)
print("Reversed:", arr[::-1])
Original: [1 3 5 7 9]
Reversed: [9 7 5 3 1]
Reversing Multi-Dimensional Arrays
Reversing 2D arrays requires specifying which axis to reverse.
import numpy as np
arr_2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print("Original 2D array:")
print(arr_2d)
# Reverse both rows and columns (complete flip)
both = arr_2d[::-1, ::-1]
print("
Reversed both axes:")
print(both)
# Reverse rows only (flip up-down)
up_down = np.flipud(arr_2d)
print("
Flip up-down:")
print(up_down)
# Reverse columns only (flip left-right)
left_right = np.fliplr(arr_2d)
print("
Flip left-right:")
print(left_right)
Original 2D array:
[[1 2 3]
[4 5 6]
[7 8 9]]
Reversed both axes:
[[9 8 7]
[6 5 4]
[3 2 1]]
Flip up-down:
[[7 8 9]
[4 5 6]
[1 2 3]]
Flip left-right:
[[3 2 1]
[6 5 4]
[9 8 7]]
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
reversed_matrix = [row[::-1] for row in matrix[::-1]]
print("Reversed nested list:", reversed_matrix)
Quick Comparison of All Methods
| Method | Type | In-Place? | Returns | Works on |
|---|---|---|---|---|
| list[::-1] | Slicing | No (copy) | New list | List, tuple, string |
| list.reverse() | Method | Yes | None | List, array |
| reversed(list) | Built-in | No | Iterator | Any iterable |
| np.flip(arr) | NumPy | No | New array | NumPy array |
| np.flipud(arr) | NumPy | No | New array | NumPy array |
| arr[::-1] | Slicing | No | View/copy | List, NumPy array |


