python经典练习100例-37.列表排序

  • 已知一个列表,升序排序
  • for循环套用
l = [70, 5, 93, 3, 9, 2]
j = 0
for n in range(len(l) - 1):
    for i in range(j+1, len(l)):
        if l[j] > l[i]:
            l[j], l[i] = l[i], l[j]
    j += 1
print(l)

运行结果:
[2, 3, 5, 9, 70, 93]

猜你喜欢

转载自blog.csdn.net/sunjiaxing_1/article/details/115334188