This short post will show how to do a reverse loops in Python.

The first example will show how to do that in a list a and the other example how to reverse a string.

Just open up a Python interpreter and test it out.

Create a list with some values in it, like this:

L1 = ["One", "two", "three", "four", "five"]

#To print the list as it is, simply do:
print L1

#To print a reverse list, do:
for i in L1[::-1]:
    print i

We can also reverse strings, like this:

string = "Hello World"

print ' '.join(reversed(string))

d l r o W o l l e H

Leave a Reply

Your email address will not be published. Required fields are marked *