List reverse can be done using more than one way.
As mentioned in previous answers two are very prominent, one with reverse()
function and two with slicing feature. I'm giving some insights on which one we should prefer.
We should always use reverse()
function for reversal of a Python list. Two reasons, one in-place reversal and two faster than other.
I've some figures to support my answer,
In [15]: len(l)
Out[15]: 1000
In [16]: %timeit -n1 l.reverse()
1 loops, best of 3: 7.87 µs per loop
In [17]: %timeit -n1 l[::-1]
1 loops, best of 3: 10 µs per loop
For 1000 integer list, reverse()
function performed better compared to slicing.