#bubble sort using indefinite iteration #on a randomly generated list of numbers #running many times will give an idea as #to efficiency import random theList = [] while len(theList) < 9: number = random.randint(1, 9) if number not in theList: theList.append(number) print("Here's the list before sorting:") print(theList) print() input("Press any key to sort it") print() 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)