a = [9,7,3,6,5,4,1,0,2,8] for k in range(len(a)): tag = True for i in a[0:-1]: # print(a.index(i),'',a[a.index(i)]) if (a[a.index(i)] > a[a.index(i) + 1]): temp = a[a.index(i) + 1] a[a.index(i) + 1] = a[a.index(i)] a[a.index(i)] = temp tag=False if tag: print("排序完成!") print(a) break