hawk

导航

2011年11月16日 #

python 实现的 直接插入排序法

摘要: str=input('plz input some numbers for sorting without any separate')doit=list(str)for a in range(1,len(doit)): for b in range(a): if doit[a] > doit[b]: continue else: substitute=doit[a] del doit[a] doit.insert(b,substitute) breakprint(doit)自己写的直接插入排序法,正在不断学习python中。。。 阅读全文

posted @ 2011-11-16 16:17 hawkgogo 阅读(200) 评论(0) 推荐(0) 编辑

python 中 sort()函数所带的参数

摘要: >>> a=range(10)>>> b=a[::-1]>>> a[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> b[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]>>> c=zip(a,b)>>> c[(0, 9), (1, 8), (2, 7), (3, 6), (4, 5), (5, 4), (6, 3), (7, 2), (8, 1), (9, 0)]>>> c.sort(key=lambda x:x[0])>>> 阅读全文

posted @ 2011-11-16 14:31 hawkgogo 阅读(821) 评论(0) 推荐(0) 编辑