def bubble_sort( the_seq ): '''Sinks the largest item to the bottom in each round''' '''The iterations stop when there is no more swap''' n = len( the_seq ) for i in range( n - 1, 0, -1 ) : swap = False for j in range( i ) : if the_seq[j] > the_seq[j + 1] : # swap the two items tmp = the_seq[j] the_seq[j] = the_seq[j + 1] the_seq[j + 1] = tmp swap = True if swap == False: # everything is in order break