newlist = oldlist[::-1]
The [::-1] slicing (which my wife Anna likes to call "the Martian smiley";-) means: slice the whole sequence, with a step of -1, i.e., in reverse. It works for all sequences.
Note that this (and the alternatives you mentioned) is equivalent to a "shallow copy", i.e.: if the items are mutable and you call mutators on them, the mutations in the items held in the original list are also in the items in the reversed list, and vice versa. If you need to avoid that, a copy.deepcopy (while always a potentially costly operation), followed in this case by a .reverse, is the only good option.
newlist = oldlist[::-1]
The [::-1] slicing (which my wife Anna likes to call "the Martian smiley";-) means: slice the whole sequence, with a step of -1, i.e., in reverse. It works for all sequences.
Note that this (and the alternatives you mentioned) is equivalent to a "shallow copy", i.e.: if the items are mutable and you call mutators on them, the mutations in the items held in the original list are also in the items in the reversed list, and vice versa. If you need to avoid that, a copy.deepcopy (while always a potentially costly operation), followed in this case by a .reverse, is the only good option.
Now let's timeit. Hint: Alex's [::-1] is fastest :)
$ p -m timeit "ol = [1, 2, 3]; nl = list(reversed(ol))"
100000 loops, best of 3: 2.34 usec per loop
$ p -m timeit "ol = [1, 2, 3]; nl = list(ol); nl.reverse();"
1000000 loops, best of 3: 0.686 usec per loop
$ p -m timeit "ol = [1, 2, 3]; nl = ol[::-1];"
1000000 loops, best of 3: 0.569 usec per loop
$ p -m timeit "ol = [1, 2, 3]; nl = [i for i in reversed(ol)];"
1000000 loops, best of 3: 1.48 usec per loop
$ p -m timeit "ol = [1, 2, 3]*1000; nl = list(reversed(ol))"
10000 loops, best of 3: 44.7 usec per loop
$ p -m timeit "ol = [1, 2, 3]*1000; nl = list(ol); nl.reverse();"
10000 loops, best of 3: 27.2 usec per loop
$ p -m timeit "ol = [1, 2, 3]*1000; nl = ol[::-1];"
10000 loops, best of 3: 24.3 usec per loop
$ p -m timeit "ol = [1, 2, 3]*1000; nl = [i for i in reversed(ol)];"
10000 loops, best of 3: 155 usec per loop
Update: Added list comp method suggested by inspectorG4dget. I'll let the results speak for themselves.
python - How do I reverse a list or loop over it backwards? - Stack Overflow
How to reverse a Python list (3 methods)
Lazy Reverse Method in O(1) Time
Reversing a simple list without reverse function
Videos
To get a new reversed list, apply the reversed function and collect the items into a list:
>>> xs = [0, 10, 20, 40]
>>> list(reversed(xs))
[40, 20, 10, 0]
To iterate backwards through a list:
>>> xs = [0, 10, 20, 40]
>>> for x in reversed(xs):
... print(x)
40
20
10
0
>>> xs = [0, 10, 20, 40]
>>> xs[::-1]
[40, 20, 10, 0]
Extended slice syntax is explained here. See also, documentation.
There are three methods you can use to reverse a list:
An in-place reverse, using the built-in reverse method that every list has natively
Using list slicing with a negative step size, resulting in a new list
Create a reverse iterator, with the reversed() function
You can try this for yourself too. Click here to open a runnable/editable example.
Why not make the list.reverse method in Python perform a lazy reverse? Instead of changing the underlying structure, it would adjust array operations so that [i] becomes [-i-1] and all iterations go backwards. This way, the list would appear reversed without actually modifying its structure.
The list would maintain this lazy reverse state for operations like insert, remove, index, iteration, and array access/editing. If an operation like + or .append is called, only then would the list be physically reversed.
In most programs, lists aren't typically appended to after being reversed. Implementing this could save time, making reversing an O(1) operation.
Note: Lazy reverse could be off by default, where you have to specify a parameter to be true to turn it on, or it could be a separate method.