Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python loop list from last to first

# credit to the Stack Overflow user in the source link
>>> a = ["foo", "bar", "baz"]
>>> for i in reversed(a):
...     print(i)
... 
baz
bar
foo
# in case you want to keep track of the index
>>> for i, e in reversed(list(enumerate(a))):
...     print(i, e)
... 
2 baz
1 bar
0 foo
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #loop #list
ADD COMMENT
Topic
Name
8+4 =