import jieba
monsters = ['国丈', '虎力大仙', '赛太岁', '鹿力大仙', '玉面公主', '白衣秀士',
 '九头虫', '黄风怪', '羊力大仙', '九灵元圣', '辟尘大王', '凌虚子',
 '黑鱼精', '如意真仙', '六耳猕猴', '美后', '黄狮精',
 '辟寒大王', '特处士', '老鼋', '寅将军', '辟暑大王', '灵感大王', '熊山君']

temp_list = []

f = open(r"西游记.txt", encoding="utf-8", mode='r')
for line in f.readlines():
    for each in line:
        if each in [' ', ' ', '\t', '\n', '。', ',', '(', ')', '/', '-',
                    '(', ')', ':', '□', '?', '!', '[', ']', ':',
                    '《', '》', '、', ';', '“', '”', '……']:
            continue
        else:
            temp_list.append(each.strip())
temp_list2 = "".join(temp_list)
counts = {} 
for monster in monsters:
    counts[monster] = temp_list2.count(monster)

items = list(counts.items())  # 将键值对转换成列表
items.sort(key=lambda x: x[1], reverse=True)  # 根据词语出现的次数进行从大到小排序

for i in range(20):
    word, count = items[i]
    print("{0:<5}{1:>5}".format(word, count))


f.close()