li = [21,3,4,58,6] for n in range(1,len(li)): # print(n) # print(li) for s in range(len(li)-n): # print(s) if li[s] > li[s+1]: ret = li[s] li[s] = li[s+1] li[s+1] = ret print(li)