# 【Python 基础】列表中的元素排序例子

x is: 0 y is: 1
mylist[x] is: 3 mylist[y] is: 5
[3, 5, 2, 1, 8, 4]
[3, 5, 2, 1, 8, 4]

x is: 0 y is: 2
mylist[x] is: 3 mylist[y] is: 2
[3, 5, 2, 1, 8, 4]
exchanged
[2, 5, 3, 1, 8, 4]

x is: 0 y is: 3
mylist[x] is: 2 mylist[y] is: 1
[2, 5, 3, 1, 8, 4]
exchanged
[1, 5, 3, 2, 8, 4]

x is: 0 y is: 4
mylist[x] is: 1 mylist[y] is: 8
[1, 5, 3, 2, 8, 4]
[1, 5, 3, 2, 8, 4]

x is: 0 y is: 5
mylist[x] is: 1 mylist[y] is: 4
[1, 5, 3, 2, 8, 4]
[1, 5, 3, 2, 8, 4]

x is: 1 y is: 2
mylist[x] is: 5 mylist[y] is: 3
[1, 5, 3, 2, 8, 4]
exchanged
[1, 3, 5, 2, 8, 4]

x is: 1 y is: 3
mylist[x] is: 3 mylist[y] is: 2
[1, 3, 5, 2, 8, 4]
exchanged
[1, 2, 5, 3, 8, 4]

x is: 1 y is: 4
mylist[x] is: 2 mylist[y] is: 8
[1, 2, 5, 3, 8, 4]
[1, 2, 5, 3, 8, 4]

x is: 1 y is: 5
mylist[x] is: 2 mylist[y] is: 4
[1, 2, 5, 3, 8, 4]
[1, 2, 5, 3, 8, 4]

x is: 2 y is: 3
mylist[x] is: 5 mylist[y] is: 3
[1, 2, 5, 3, 8, 4]
exchanged
[1, 2, 3, 5, 8, 4]

x is: 2 y is: 4
mylist[x] is: 3 mylist[y] is: 8
[1, 2, 3, 5, 8, 4]
[1, 2, 3, 5, 8, 4]

x is: 2 y is: 5
mylist[x] is: 3 mylist[y] is: 4
[1, 2, 3, 5, 8, 4]
[1, 2, 3, 5, 8, 4]

x is: 3 y is: 4
mylist[x] is: 5 mylist[y] is: 8
[1, 2, 3, 5, 8, 4]
[1, 2, 3, 5, 8, 4]

x is: 3 y is: 5
mylist[x] is: 5 mylist[y] is: 4
[1, 2, 3, 5, 8, 4]
exchanged
[1, 2, 3, 4, 8, 5]

x is: 4 y is: 5
mylist[x] is: 8 mylist[y] is: 5
[1, 2, 3, 4, 8, 5]
exchanged
[1, 2, 3, 4, 5, 8]

[1, 2, 3, 4, 5, 8] <<<< 最终的结果


Original: https://www.cnblogs.com/gaojian/p/15975361.html
Author: 健哥的数据花园
Title: 【Python 基础】列表中的元素排序例子

(0)