lst = [1,9,8,6,3,4,5,2,7] for i in range(9): for j in range(8-i): if lst[j]>lst[j+1]: lst[j],lst[j+1] = lst[j+1],lst[j] print(lst)