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))