冒泡排序和range函数
代码
TestList1=[1,90,12,56,2,5]
print TestList1
for i in range(0,len(TestList1)):
for j in range(i,len(TestList1)):
if TestList1[i] > TestList1[j]:
TestList1[i],TestList1[j] = TestList1[j],TestList1[i]
print '*'*20
print TestList1
result:
[1, 90, 12, 56, 2, 5]
********************
[1, 2, 5, 12, 56, 90]
Work for fun,Live for love!