list = [13, 22, 6, 99, 11]
for m in range(len(list)-1):
for n in range(m+1, len(list)):
if list[m]> list[n]:
temp = list[n]
list[n] = list[m]
list[m] = temp
print list
结果:
[6, 11, 13, 22, 99]
分析:
list = [13, 22, 6, 99, 11]
for i in range(len(list)-1):
for j in range (i+1,len(list)):
# print str(i)
# print "init--" + str(j)
print '本次进行比较的list下标值' + str(i),str(j)
if list[i] > list[j]:
# print i,j
# print '-----' + str(list[i]) + str(list[j]) + '-------'
T = list[j]
list[j]= list[i]
list[i]=T
#