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
You can also use the bitwise complement of the array index to step through the array in reverse:
>>> array = [0, 10, 20, 40] >>> [array[~i] for i, _ in enumerate(array)] [40, 20, 10, 0]
Whatever you do, don't do it this way ;)