#efficient bubble sort using indefinite iteration #to check whether anything has been swapped theList = [9, 4, 6, 2, 7, 8, 1, 5, 3] swap = True passes = 0 while swap: swap = False passes = passes + 1 for i in range(0, len(theList)-1): if theList[i] > theList[i+1]: theList[i], theList[i+1] = theList[i+1], theList[i] swap = True print("sorted") print(theList) print(passes)