标签:bre pytho rate pen 练习 ISE insert turn enumerate
排序
----------------------------------------------------------------
lst = [5,10,2,4,8,1]
def sort(item,reverse=False):
ret = []
for i in item:
for x,y in enumerate(ret): #[10,5]
flage=i>y if reverse else i<y
if flage:
ret.insert(x,i)
break
else:
ret.append(i)
return ret
*************
lst = [5,10,2,4,8,1]
def sort(item,reverse=True):
ret = []
def choise(a,b):
flage = a > b if reverse else a < b
return flage
for i in item:
for x,y in enumerate(ret): #[10,5]
if choise(i,y):
ret.insert(x,i)
break
else:
ret.append(i)
return ret
print(sort(lst))
*************
def choise(a, b,reverse):
flage = a > b if reverse else a < b
return flage
lst = [5,10,2,4,8,1]
def sort(item,reverse=False):
ret = []
for i in item:
for x,y in enumerate(ret): #[10,5]
if choise(i,y,reverse):
ret.insert(x,i)
break
else:
ret.append(i)
return ret
print(sort(lst))
------------------------------------------------
标签:bre pytho rate pen 练习 ISE insert turn enumerate
原文地址:https://www.cnblogs.com/centos-kang/p/12189188.html