Oct 13, 2017

Reverse the list in Python

testList = [1, 3, 5]
testList.reverse()
print(testList)

#-> [5, 3, 1]

>>> for element in reversed([1,3,5]):
...     print(element)
... 
5
3

1


>>> "Test Python"[::-1]

'nohtyP tseT'

>>> [1, 3, 5][::-1]

[5, 3, 1]