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.

Related questions

0 votes
asked May 11, 2023 in Python Flask by sharadyadav1986
0 votes
asked May 10, 2023 in Python Flask by john ganales
...