python练习代码

排序

----------------------------------------------------------------

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 retprint(sort(lst))*************
def choise(a, b,reverse):    flage = a > b if reverse else a < b    return flagelst = [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 retprint(sort(lst))------------------------------------------------

相关推荐