How can I do the following in Python?
array = [0, 10, 20, 40]
for (i = array.length() - 1; i >= 0; i--)
I need to have the elements of a
There are 3 methods to get the reversed list:
Slicing Method 1: reversed_array = array[-1::-1]
Slicing Method 2:
reversed_array2 = array[::-1]
Using the builtin function: reversed_array = array.reverse()
The third function actually reversed the list object in place. That means no copy of pristine data is maintained. This is a good approach if you don't want to maintain the old version. But doesn't seem to be a solution if you do want the pristine and reversed version.