python练习:字符串中的数字排序
#字符串中的字数排序 b = ‘1534788912‘ print ("将b排序显示,办法(列表):") listb = list(b) #[‘1‘, ‘5‘, ‘3‘, ‘4‘, ‘7‘, ‘8‘, ‘8‘, ‘9‘, ‘1‘, ‘2‘] for i in range(0, len(listb)-1): for j in range(0,len(listb)-1): if int(listb[j]) > int(listb[j+1]): listb[j], listb[j+1] = listb[j+1], listb[j] i+=1 print (listb) #[‘1‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘7‘, ‘8‘, ‘8‘, ‘9‘] newb = ‘‘ for item in listb: newb = newb+item print(newb)
#字符串中的字数排序 b = ‘1534788912‘ print ("将b排序显示,办法2(列表排序):") listb = list(b) #[‘1‘, ‘5‘, ‘3‘, ‘4‘, ‘7‘, ‘8‘, ‘8‘, ‘9‘, ‘1‘, ‘2‘] listb.sort() print (listb) #[‘1‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘7‘, ‘8‘, ‘8‘, ‘9‘] newb = ‘‘ for item in listb: newb = newb+item print(newb) #1123457889
#字符串中的字数排序b = ‘1534788912‘print ("将b排序显示,办法(列表):")listb = list(b) #[‘1‘, ‘5‘, ‘3‘, ‘4‘, ‘7‘, ‘8‘, ‘8‘, ‘9‘, ‘1‘, ‘2‘]for i in range(0, len(listb)-1):for j in range(0,len(listb)-1):if int(listb[j]) > int(listb[j+1]):listb[j], listb[j+1] = listb[j+1], listb[j] i+=1print (listb) #[‘1‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘7‘, ‘8‘, ‘8‘, ‘9‘]newb = ‘‘for item in listb:newb = newb+itemprint(newb)
相关推荐
zlxcsdn 2020-09-13
listep 2020-09-11
jokewinl 2020-07-18
liuyang000 2020-04-25
rein0 2020-04-18
wordmhg 2020-04-09
wangqing 2020-04-06
chaoxiao 2020-03-07
horizonheart 2020-02-16
adonislu 2020-02-14
sschencn 2020-02-14
嗡汤圆 2020-02-02
yuanran0 2020-01-30
shawsun 2020-01-20
wuxiaosi0 2020-01-08
yedaoxiaodi 2020-01-04
zhglinux 2020-01-03
程松 2020-01-01