code is simple
def bubble_sort(l):
for i in xrange(0, len(l)-1) :
for n in xrange(0, len(l)) :
if l[i] > l[i+1] :
l[i], l[i+1] = l[i+1], l[i]
lst = [[1, 8, 2], [3, 2, 5], [2, 13, 3], [2, 5, 5], [2, 5, 6], [5, 11, 6], [5, 5, 6]]
print(lst)
bubble_sort(lst)
print(lst)
result:
[[1, 8, 2], [3, 2, 5], [2, 13, 3], [2, 5, 5], [2, 5, 6], [5, 11, 6], [5, 5, 6]]
[[1, 8, 2], [2, 13, 3], [2, 5, 5], [2, 5, 6], [3, 2, 5], [5, 5, 6], [5, 11, 6]]
the sort is not correct.
why?
The problem is that you’re making only one iteration, while in bubble sort you should iterate over and over again until there are no swapped pairs anymore. Like this: