英文词频统计预备,组合数据类型练习

1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。

str='''Leshi Holding (Beijing) Co, the company controlled by LeEco founder Jia Yueting, has repaid debt of more than 100 million yuan ($15 million) to its suppliers, according to a report by Securities Daily.

"Leshi Holding signed repayment deals with 28 suppliers last week and will do it with another 27 suppliers this week," a Leshi Holding insider told Securities Daily on Tuesday.

Most of the suppliers that have reached settlements with Leshi Holding are smartphone store contractors of LeMobile's LePhone, the report said.'''
for i in ',.?':
    str=str.replace(i,' ')

str=str.lower()
write=str.split(' ')
print(str)
print(str.count('it'))

2.

列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。

g=list('12313561325')
for i in range(len(g)):
    g[i]=int(g[i])
print(g)
print('第1个3分下标为:',g.index(3))
print('1分的有:',g.count(1))
print('3分的有:',g.count(3))

3.简要描述列表与元组的异同。

列表和元组都是序列类型,不过元组是不可变的。即你不能修改元组。元组通过圆括号中用逗号分隔的项目定义。

 

posted @ 2017-09-20 20:51  003蒋宇翔  阅读(123)  评论(0编辑  收藏  举报