list1 = [13, 654, 965, 784, 2326, 945, 3231]
list_length = len(list1)
for i in range(list_length):
for j in range(i + 1, list_length):
if list1[i] > list1[j]:
list1[i], list1[j] = list1[j], list1[i]
print(list1)
# 输出
[13, 654, 784, 945, 965, 2326, 3231]
Process finished with exit code 0
当然直接调用python的sort()、sorted()会更加简单