D
Size: a a a
D
Я⠀
AR
K3
Р
PT
M
M
RB
RB
RB
M
M
RB
RB
M
# reverse - Best way to create a "reversed" list in Python?
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.
RB