第四次作业——蔡李鸿

from datetime import datetime
start_day=datetime(2019,4,1)
end_day=datetime(2019,4,30)
count = 0
print("\t\t\t2019年4月\n")
print("星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期天")
for i in range (0,30):
    i=i+1
    print(i,end="\t")
    count=count+1
    if count%7==0:
        print("\n")

  

import jieba
excludes = {"什么","一个","我们","那里","你们","如今","说道","知道","起来","姑娘","这里","出来","他们","众人","自己",
            "一面","只见","太太","奶奶","两个","没有","不是","不知","这个","听见","这样","进来","咱们","告诉","怎么",
            "就是","东西","回来","只是","老爷","大家","只得","丫头","这些","不敢","出去","所以","的话","不好","姐姐",
            "鸳鸯"}
txt = open("C:\Users\红楼梦.txt", "r", encoding='utf-8').read()
words  = jieba.lcut(txt)
#print(type(words)) 
counts = {}  
for word in words:
    if len(word) == 1:
        continue
    elif word == "宝玉" or word == "贾宝玉"or word=="绛洞花主"or word=="怡红公子"or word=="浊玉"or word=="槛内人":
        rword = "宝二爷"
    elif word == "黛玉" or word == "林黛玉" or word=="林妹妹" or word=="林姑娘" or word=="潇湘妃子"or word=="颦颦":
        rword = "颦儿"
    elif word == "凤姐儿" or word == "王熙凤" or word=="凤丫头"or word=="琏二奶奶"or word=="凤辣子" or word=="凤姐":
        rword = "凤哥儿"
    elif word == "贾母" or word == "老太太":
        rword = "贾母"
    elif word == "宝丫头" or word == "薛宝钗"or word == "宝姑娘" or word == "宝钗" or word == "宝姐姐":
        rword = "蘅芜君"

    else:
        rword = word
    counts[rword] = counts.get(rword,0) + 1 
for word in excludes:
    del(counts[word])  
items = list(counts.items())

items.sort(key=lambda x:x[1], reverse=True)

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

  

猜你喜欢

转载自www.cnblogs.com/cailihong/p/10841087.html