How to Reverse a List in Python
Published in
1 min readJan 15, 2019
Reverse an array in Python using slicing, reversed generator and reverse method to replace a list in-place
numbers = [1, 2, 3, 4, 5]# Slice the list
numbers[::-1]
>>> [5, 4, 3, 2, 1]# reversed generator
list(reversed(numbers))
>>> [5, 4, 3, 2, 1]# reverse method to reverse the list in-place
numbers.reverse()
print(numbers)
>>> [5, 4, 3, 2, 1]
Like this on Twitter | Like this on Instagram | Like this on Facebook
Subscribe to our newsletter
Originally published at pythonpips.com.