# 查找 排序
k1 = [11,22,1, 2, 3, 4, 5, 6, 7, 8, 9, ]
k1.sorted() # 排序改变
k1[1] , k1[2] = k1[2] ,k1[1]
print(k1)
# [11, 1, 22, 2, 3, 4, 5, 6, 7, 8, 9]
#运用变量交换 ---- k1[i] , k1[i+1] = k1[i+1] ,k1[i] 相邻互换位置
# for in 循环比较
k1 = [11,22,1, 2, 3, 4, 5, 6, 9, 8, 9, ]
for j in range(len(k1)-1):
for i in range(len(k1)-1-j):
if k1[i] > k1[i+1]:
k1[i], k1[i + 1] = k1[i + 1], k1[i]
print(k1)
# [1, 2, 3, 4, 5, 6, 8, 9, 9, 11, 22]
k1 = [11,22,1, 2, 3, 4, 5, 6, 7, 8, 9, ]
for i in range(len(k1)-1):
for i in range(len(k1) - 1):
if k1[i] > k1[i+1]:
k1[i] , k1[i+1] = k1[i+1] ,k1[i]
print(k1)
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22]
for i in range(len(k1)-1): # for in 陷入循环 列表
if k1[i] > k1[i+1]:
k1[i], k1[i + 1] = k1[i + 1], k1[i]
print(k1)
# [11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 22]