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

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

d='''If I had to live my life without you near me

The days would all be empty

The nights would seem so long

With you I see forever oh so clearly

I might have been in love before

But it never felt this strong

Our dreams are young And we both know

they'll take us where we want to go

Hold me now

Touch me now

I don't want to live without you

Nothing's gonna change my love for you

You ought to know by now how much I love you

One thing you can be sure of

I'll never ask for more than your love

Nothing's gonna change my love for you

You ought to know by now how much I love you

The world may change my whole life through

But nothing's gonna change my love for you

If the road aheadis not so easy,

Our love will lead the way for us

Just like a guiding star

I'll be there for you if you should need me

You don't have to change a thing

I love you just the way you are

So come with me and share the view

I'll help you see forever too

Hold me now

Touch me now

I don't want to live without you

Nothing's gonna change my love for you

You ought to know by now how much I love you

One thing you can be sure of

I'll never ask for more than your love'''
a=d.lower()
b=d.replace(',',' ')
c=d.replace('!',' ')
d=d.split(' ')
print('I出现的次数:',d.count('I'))
print('you出现的次数:',d.count('you'))
print('改变后的英文歌曲:',d)

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

lis = [1,2,3,2,1,2,3,2]
print('原始的lis=',lis)
lis.append(3)
print('在末尾添加一个3:lis=',lis)
lis.insert(3,2)
print('在下标为3的地方插入一个2,lis=',lis)
del lis[2]
print('删除下标为2的数,lis=',lis)

lis = list(map(int, lis))

print('第一个3的下标为:',lis.index(3))

print('1出现的次数为:',lis.count(1))
print('3出现的次数为:',lis.count(3))

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

元组是不可变的,不可以进行添加、删除或修改;

列表是可变的,可以进行添加、查询或修改的操作.

posted @ 2017-09-22 17:14  林丹宜  阅读(121)  评论(0)    收藏  举报