How do I have the algorithm below to sort my list in opposite direction (right to left) instead of left to right.
Also, how do I make it sort simultaneously or alternatively in both directions? Thanks.

def bubblesort(l):
    for passes in range(len(l)-1, 0, -1):
        for index in range(passes):
            if l[index] < l[index + 1]:
                l[index], l[index + 1] = l[index + 1], l[index]
                print l
    return l

bubblesort([4,2,7,9,25])

Editor:
Please use code tags with your code to preserve the indentations. Otherwise the code is very difficult to read and not too many folks will help.

[code=python]
your Python code here

[/code]

In your code line:
if l[index] < l[index + 1]:
use:
if l[index] > l[index + 1]:
for ascending sort order.

BTW, programmers avoid using the letter l for a variable name, since it looks so much like 1.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.