新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
python列表排序
代碼如下:
我們提供的服務(wù)有:成都做網(wǎng)站、成都網(wǎng)站制作、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、宿州ssl等。為1000多家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的宿州網(wǎng)站制作公司
def getprice(item):
# 切分,獲取名字與價格
name,price=item.split(":")
# 字符串轉(zhuǎn)整數(shù),并返回
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)
執(zhí)行結(jié)果:
名稱欄目:python列表排序
當(dāng)前路徑:http://fisionsoft.com.cn/article/ghhdop.html