def bubbleSort(array): isSorted =False# After one iteration, the last element in the array will be in the correct position.# `counter` is to Keep track of how many elements are there in the correct position counter =0whilenot isSorted: isSorted =Truefor i inrange(len(array) -1- counter): # Don't go till last elementif array[i] > array[i+1]: swap(array,i,i+1) isSorted =False# If a swap is done, then the array may not be sorted counter +=1# Increment the countryreturn array# Helper functiont to swap the arraydef swap(array,j,k): array[j],array[k] = array[k],array[j]