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

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

song='''I messed up tonight, I lost another fight
I still mess up but I'll just start again
I keep falling down, I keep on hitting the ground
I always get up now to see what's next
Birds don't just fly, they fall down and get up
Nobody learns without getting it won
I won't give up, no I won't give in
Til I reach the end, then I'll start again
No I won't leave, I wanna try everything
I wanna try even though I could fail
I won't give up, no I won't give in
Til I reach the end and then I'll start again
No I won't leave, I wanna try everything
I wanna try even though I could fail'''
song=song.lower()
for i in ',':
    song=song.replace(i,' ')
print(song)
words=song.split(' ')
print(words)

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

grades=list('12313561325')
for i in range(len(grades)):
    grades[i]=int(grades[i])
print(grades)
print(grades.index(3))
print(grades.count(1))
print(grades.count(3))

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

 答:列表和元组非常类似,有时候他们都干一样的事情。但他们最大的区别是元组一旦被赋值,值不可以被改变,一旦改变就会出错;但是列表可以任意的更改。其次的区别是他们用不同的符号表示,复制的时候,列表用方括号[],而元组用小括号()。

posted @ 2017-09-20 19:03  004熊锋阳  阅读(97)  评论(0)    收藏  举报