组合数据类型练习,英文词频统计实例上
- 字典实例:建立学生学号成绩字典,做增删改查遍历操作。
- 列表,元组,字典,集合的遍历。
- 总结列表,元组,字典,集合的联系与区别。 列表可重复,类型可不同。类型不同也就是跟数组最本质的区别。元组和列表在结构上没有什么区别,唯一的差异是元组是只读,不能修改。集合没有特殊的表示方法,而是通过一个set函数转换成集合。字典存储键值对数据,字典最外面用大括号,每一组用冒号连起来,然后各组用逗号隔开。列表跟字典相比,字典查找和插入的速度极快,不会随着key的增加而变慢,需要占用大量的内存,内存浪费多。而列表查找和插入的时间随着元素的增加而增加,占用空间小,浪费内存极少。
- 英文词频统计实例
- 待分析字符串
- 分解提取单词
- 大小写 txt.lower()
- 分隔符'.,:;?!-_’
- 单词列表
- 单词计数字典
n='''Girls at a training course offered by the "Care for Girls" program in Qingjian county, Shaanxi province, talked about their pursuit of dreams despite living in unfavorable conditions.Initiated by the National Health and Family Planning commission in 2013, the program helps girls in underdeveloped regions to build their self-esteem and self-confidence.Xi Peiyao, 12, who attended the training course, said her dream is to be a teacher.She is living with her mother in a room that has no bathroom and costs 300 yuan ($48) a month to rent. Merit certificates she received from school are displayed on the wall. Yan Lingling, Xi's mother, said she is proud of her daughter.'''
n=n.lower()
n=n.replace('\n',' ')
word=n.split(' ')
dic={}
keys=set(word)
for i in keys:
dic[i]=word.count(i)
print(dic)