python创建字典,并且排序

word_dict = {}
#exclude_str = ",。!?、()【】<>《》=:+-*—“”…"
for char in temp_pro:
    #for char in temp_pro[i]:
        #if char not in exclude_str:
            if char not in word_dict:  # 为了去掉空白
                word_dict[char] = 1
            else:
                word_dict[char] += 1
lstWords = sorted(word_dict.items(), key=lambda x: x[1], reverse=True)
 
 
#reverse=True这个是允许覆盖的意思

猜你喜欢

转载自blog.csdn.net/qinglv1/article/details/80508145