array=[0,10,20,40]
for i in reversed(array):
print i
The reversed()
function returns list_reversiterator
instead of list
.
If you want to do return
, you must write list(reversed(array))
.
This method uses the property that L[:-1]
returns the list [40, 20, 10, 0]
that has flipped L.
L = [0,10,20,40]
for i in L[::-1]:
print i
© 2024 OneMinuteCode. All rights reserved.