uhskuq
Last Updated: February 25, 2016
·
5.304K
· xiaoba
3b6236efa4fd7dfd2b6c4a7c20bb8c83

reverse array in python

a = [1,2,3,4,5]
reverse_a = a[::-1]
Say Thanks
Respond

1 Response
Add your response

4852
Ebc47ee771e1695743e6b79c0821f37f

If you want to reverse the list in place you can do:

>>> foo = [1, 2, 3, 4, 5]
>>> foo.reverse()
>>> foo
[5, 4, 3, 2, 1]

That way you don't have to keep a copy of the list in memory.

over 1 year ago ·