Python reverse a list
You can make use of the reversed function for this as:
>>> array=[0,10,20,40]
>>> for i in reversed(array):
... print(i)Note that reversed(...) does not return a list. You can get a reversed list using list(reversed(array)).
According to the above link to, "Compared to extended slicing, such as range(1,4)[::-1], reversed() is easier to read, runs faster, and uses substantially less memory.
Last updated