def bubble_sort(list): for i in range(len(list)): for j in (range(i,len(list))): if list[j] < list[i]: temp = list[j] list[j] = list[i] list[i] = temp
list = [2,3,4,1,7,4,3,0,9]
bubble_sort(list)
list
[0, 1, 2, 3, 3, 4, 4, 7, 9]
原文:http://blog.csdn.net/ilovezhangxian/article/details/38514609