fork download
  1. def bubble_pass(original):
  2. counter = 0
  3. for i, v in enumerate(original[:-1]): #:-1 so it doesn't try to compare the last number to the non-existant one after it
  4. print str(i) + ": " + str(v)
  5. if v > original[i+1]:
  6. original[i], original[i+1] = original[i+1], original[i]
  7. counter += 1
  8. return counter, original
  9.  
  10. steps, sorted_list = bubble_pass([1, 4, 3, 2, 6, 5])
  11.  
Success #stdin #stdout 0.02s 9016KB
stdin
Standard input is empty
stdout
0: 1
1: 4
2: 3
3: 2
4: 6