博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第四次作业
阅读量:5086 次
发布时间:2019-06-13

本文共 2164 字,大约阅读时间需要 7 分钟。

1.初始化start_day,end_day两个日期

from datetime import datetime
start_day=datetime(2019,4,1)
end_day=datetime(2019,4,30)
其它时间数据生成要用datetime或date模块的方法编程实现
2.不能使用calendar模块生成

from datetime import datetime

from datetime import timedelta
from datetime import *
start_day = datetime(2019, 4, 1)
end_day = datetime(2019, 4, 30)
a=end_day-start_day
amount = a.days + 1
first=start_day.isoweekday()
k = 1
count=0
print("\t\t\t2019年4月")
print("星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期日")
while k < first:
k=k+1
print("\t", end="")
p = 1
while p <= amount:
print(p, "\t", end="")
p =p+1
count =count+1
if (count % 7 == 0):
print("\n")

1.参考“三国演义”词频统计程序,实现对红楼梦出场人物的频次统计。

2.(可选)
将红楼梦出场人物的频次统计结果用词云显示。import jieba

excludes = {"什么","一个","我们","那里","你们","如今","说道","知道","起来","这里","出来","他们","众人","自己",

"奶奶","一面","只见","怎么","姑娘","两个","没有","不是","不知","这个","听见","这样","进来","这是",
 "告诉","就是","咱们","东西","回来","只是","大家","老爷","只得","丫头","这些","不敢","出去","所以",
"不过","的话","不好","姐姐"}
txt = open("红楼梦.txt", "r", encoding='utf8').read()
words = jieba.lcut(txt)
counts = {}
 for word in words:
 if len(word) == 1:
 continue
elif (word == "宝玉" or word == "宝玉道"or word == "宝二爷"
 or word == "混世魔王"or word == "怡红公子"or word == "绛洞花主"
 or word == "无事忙"or word == "遮天大王"or word == "富贵闲人"or word =="贾宝玉"):
rword = "贾宝玉"
 elif word == "黛玉" or word == "黛玉道"or word =="林黛玉":
 rword = "林黛玉"
 elif word == "宝钗" or word == "宝钗道"or word =="薛宝钗":
 rword = "薛宝钗"
 elif word == "姨太太" or word == "薛姨妈":
 rword = "薛姨妈"
elif word == "老祖宗" or word == "老太太"or word == "史太君"or word =="贾母":
 rword = "贾母"
 elif word == "太太" or word == "二太太":
 rword = "王夫人"
 elif word == "熙凤" or word == "熙凤道"or word == "凤姐"or word == "凤姐儿"or word == "王熙凤":
 rword = "王熙凤"
 elif word == "平儿" or word == "袭人"or word == "小平":
 rword = "平儿"
 elif word == "探春" or word == "探春道":
 rword = "贾探春"
elif 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:>7}".format(word, count))

 

转载于:https://www.cnblogs.com/xxxx2/p/10841083.html

你可能感兴趣的文章
日常开发时遇到的一些坑(三)
查看>>
Eclipse 安装SVN插件
查看>>
深度学习
查看>>
TCP粘包问题及解决方案
查看>>
构建之法阅读笔记02
查看>>
添加按钮
查看>>
移动端页面开发适配 rem布局原理
查看>>
Ajax中文乱码问题解决方法(服务器端用servlet)
查看>>
会计电算化常考题目一
查看>>
阿里云服务器CentOS6.9安装Mysql
查看>>
剑指offer系列6:数值的整数次方
查看>>
js 过滤敏感词
查看>>
poj2752 Seek the Name, Seek the Fame
查看>>
软件开发和软件测试,我该如何选择?(蜗牛学院)
查看>>
基本封装方法
查看>>
bcb ole拖拽功能的实现
查看>>
生活大爆炸之何为光速
查看>>
bzoj 2456: mode【瞎搞】
查看>>
[Typescript] Specify Exact Values with TypeScript’s Literal Types
查看>>
[GraphQL] Reuse Query Fields with GraphQL Fragments
查看>>