Bubble Sort

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 = 0 

    while not isSorted:
        isSorted = True
        for i in range(len(array) - 1 - counter): # Don't go till last element
            if 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 country
    return array

# Helper functiont to swap the array
def swap(array,j,k):
    array[j],array[k] = array[k],array[j]
bubbleSort([8,5,2,9,5,6,3])
[2, 3, 5, 5, 6, 8, 9]