Life is short, you need Python

冒泡排序和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]

 

posted @ 2010-09-14 14:25  runfox545  阅读(336)  评论(0编辑  收藏  举报
白月黑羽 Python教程 白月黑羽Python