python开发冒泡排序实方案
程序员文章站
2023-02-27 18:55:03
python开发冒泡排序实方案。
# -*- coding: utf_8 -*-
print(__doc__)
dic = {}
with open('G:/...
python开发冒泡排序实方案。
# -*- coding: utf_8 -*- print(__doc__) dic = {} with open('G:/py_proj/test/flask.txt') as f: for char in f.read().replace(' ',''): if char in dic: dic[char] += 1 else: dic[char] = 1 # print(dic) rev_list = list(dic.items()) length = len(rev_list) # 冒泡排序 for i in range(length-1): for j in range(length-i-1): #j为下标识 if rev_list[j][1] > rev_list[j+1][1]: rev_list[j],rev_list[j+1] = rev_list[j+1],rev_list[j] print(rev_list) for char ,c in sorted(rev_list,key= lambda x:x[1],reverse= True): print('%s count is %d' %(char,c))
上一篇: 香港旅游注意事项 出入境及旅游小贴士
下一篇: 中国最高蹦极在哪里 中国最高蹦极地排名