In [3]:
def SimpleReversalSort(pi):
    flips = 0
    for i in xrange(len(pi)):
        j = pi.index(min(pi[i:]))
        if (j != i):
            flips += 1
            pi = pi[:i] + [v for v in reversed(pi[i:j+1])] + pi[j+1:]
            print "%2d: rho(%d,%d) = %s" % (flips, i, j, pi)
    return pi
In [5]:
test = [ 6,5,3,4,2,1 ]
print test
print SimpleReversalSort(test)
[6, 5, 3, 4, 2, 1]
 1: rho(0,5) = [1, 2, 4, 3, 5, 6]
 2: rho(2,3) = [1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]

In [4]:
 
In []: