猫史档案馆


【Python作品分享】定义排序函数【教程贴】

用户:唐城王唐城张小号唐城王唐城张小号查看:0 回复:0 评论:0 创建时间:2022-07-23T14:55:00


【作品展示】

center_image

 

【作品介绍】

gf

 

【作品源代码】

tp1 = [1, 4, -5, 喵, 78, 12, 0, 3, 3.5, 3]
def mysorted(y, reverse=False):
    y = list(y)
    s = []
    if reverse == False:
        while y:
            m = mymin(y)
            y.remove(m)
            s.append(m)
    else:
        while y:
            m = mymax(y)
            y.remove(m)
            s.append(m)
    return s
res1 = mysorted(tpl)
res2 = mysorted(tpl, True)
print('升序排列:'+str(res1))
print('降序排列:'+str(res2))

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页