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

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

yingyu='''There are moments in life when you miss someone so much that you just want to pick them from your dreams and hug them for real! Dream what you want to dream;go where you want to go;be what you want to be,because you have only one life and one chance to do all the things you want to do.

  May you have enough happiness to make you sweet,enough trials to make you strong,enough sorrow to keep you human,enough hope to make you happy? Always put yourself in others’shoes.If you feel that it hurts you,it probably hurts the other person, too.

  The happiest of people don’t necessarily have the best of everything;they just make the most of everything that comes along their way.Happiness lies for those who cry,those who hurt, those who have searched,and those who have tried,for only they can appreciate the importance of people

  who have touched their lives.Love begins with a smile,grows with a kiss and ends with a tear.The brightest future will always be based on a forgotten past, you can’t go on well in lifeuntil you let go of your past failures and heartaches.

  When you were born,you were crying and everyone around you was smiling.Live your life so that when you die,you're the one who is smiling and everyone around you is crying.

  Please send this message to those people who mean something to you,to those who have touched your life in one way or another,to those who make you smile when you really need it,to those that make you see the brighter side of things when you are really down,to those who you want to let them know that you appreciate their friendship.And if you don’t, don’t worry,nothing bad will happen to you,you will just miss out on the opportunity to brighten someone’s day with this message.'''

yingyu=yingyu.lower()
for i in ',.!?':
    yingyu=yingyu.replace(i,' ')

print(yingyu)    
    
yingyu.count('who')

who=yingyu.split(' ')
 print(who)

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

 

grade
[1, 2, 3, 2, 2, 1, 5, 3, 5]
>>> grade[1]='8'
>>> grade
[1, '8', 3, 2, 2, 1, 5, 3, 5]
>>> grade.insert(1,9)
>>> grade
[1, 9, '8', 3, 2, 2, 1, 5, 3, 5]
>>> grade.append(10)
>>> grade
[1, 9, '8', 3, 2, 2, 1, 5, 3, 5, 10]
>>> grade.pop()
10
>>> grade
[1, 9, '8', 3, 2, 2, 1, 5, 3, 5]
grade.index(3)
2
grade.count(1)
2
>>> grade.count(3)
2
>>> grade.sort()
grade
[1, 1, 2, 2, 2, 3, 3, 5, 5]

 

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

列表用大括号显示[ ]元组用小括号()显示,并且列表可以随时进行增删改,而元祖不行

posted @ 2017-09-20 18:49  007杨碧茜  阅读(210)  评论(0编辑  收藏  举报