I am trying to make a bubblesort in python from scratch, do you know why it is not working? I am getting the error list index out of range.
data = [1, 32, 50, 12, 14, 7, 45, 27, 18, 9, 19, 22, 51, 42, 4, 25, 13, 6, 21, 49, 41, 37]
def bubbleSort(alist):
length = len(alist)
for i in range(length):
first = alist[i]
second = alist[i + 1]
if first > second:
a, b = alist.index(first), alist.index(second)
alist[b], alist[a] = alist[a], alist[b]
return data
print(bubbleSort(data))
Thanks, Scott