0 votes
in Python Flask by
Explain how do you reverse a list?

1 Answer

0 votes
by
Using the reverse() method.

>>> a.reverse()
>>> a
[4, 3, 2, 1]

You can also do it via slicing from right to left:

>>> a[::-1]
>>> a
[1, 2, 3, 4]

This gives us the original list because we already reversed it once. However, this does not modify the original list to reverse it.
...