How can I do the following in Python?
array = [0, 10, 20, 40] for (i = array.length() - 1; i >= 0; i--)
array = [0, 10, 20, 40]
for (i = array.length() - 1; i >= 0; i--)
I need to have the elements of an array, but from the end to the beginning.
Simply use the below-mentioned method to reverse a list in a Python:-
>>> L = [0,10,20,40] >>> L[::-1] [40, 20, 10, 0]
>>> L = [0,10,20,40]
>>> L[::-1]
[40, 20, 10, 0]