You can use a negative step in a slice to iterate backward through a list.
Example code:
main.py88 chars4 lines
This code will print each element in the list my_list
starting from the last position to the first.
Alternatively, you can also use the reversed()
function to iterate backwards through the list.
Example code:
main.py67 chars4 lines
This will also print out the elements from last position to first.
gistlibby LogSnag