python列表排序
代码如下:
def getprice(item): # 切分,获取名字与价格 name,price=item.split(":") # 字符串转整数,并返回 return int(price)phoneprice = '魅族X8:1798,红米6:849,荣耀8X:1399,小米8:2499,小米8SE:2099,荣耀畅玩7A:699'# 字符串切分items=phoneprice.split(",")print(items)# 按照价格从小到大排序items.sort(key=getprice)print(items)
执行结果:
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。