英文词频统计预备,组合数据类型练习
2017-09-22 13:54 055李小锐 阅读(248) 评论(0) 收藏 举报1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
-
It's been a long day without you my friend And I'll tell you all about it when I see you again We've come a long way from where we began Oh I'll tell you all about it when I see you again When I see you again Damn who knew all the planes we flew Good things we've been through That I'll be standing right here Talking to you about another path I know we loved to hit the road and laugh But something told me that it wouldn't last Had to switch up look at things different see the bigger picture Those were the days hard work forever pays Now I see you in a better place How could we not talk about family when family's all that we got? Everything I went through you were standing there by my side And now you gonna be with me for the last ride It's been a long day without you my friend And I'll tell you all about it when I see you again We've come a long way from where we began Oh I'll tell you all about it when I see you again When I see you again First you both go out your way And the vibe is feeling strong and what's Small turn to a friendship a friendship Turn into a bond and that bond will never Be broke and the love will never get lost And when brotherhood come first then the line Will never be crossed established it on our own When that line had to be drawn and that line is what We reach so remember me when I'm gone How could we not talk about family when family's all that we got? Everything I went through you were standing there by my side And now you gonna be with me for the last ride Let the light guide your way hold every memory As you go and every road you take will always lead you home Hoo It's been a long day without you my friend And I'll tell you all about it when I see you again We've come a long way from where we began Oh I'll tell you all about it when I see you again When I see you again Again When I see you again see you again When I see you again >>> s.count('see you again') 12
>>> s.lower() "it's been a long day without you my friend\n\nand i'll tell you all about it when i see you again\n\nwe've come a long way from where we began\noh i'll tell you all about it when i see you again\nwhen i see you again\n\ndamn who knew all the planes we flew\ngood things we've been through\nthat i'll be standing right here\ntalking to you about another path\ni know we loved to hit the road and laugh\nbut something told me that it wouldn't last\nhad to switch up look at things different see the bigger picture\nthose were the days hard work forever pays\nnow i see you in a better place\n\nhow could we not talk about family when family's all that we got?\neverything i went through you were standing there by my side\nand now you gonna be with me for the last ride\nit's been a long day without you my friend\n\nand i'll tell you all about it when i see you again\n\nwe've come a long way from where we began\noh i'll tell you all about it when i see you again\n\nwhen i see you again\n\nfirst you both go out your way\nand the vibe is feeling strong and what's\nsmall turn to a friendship a friendship\nturn into a bond and that bond will never\nbe broke and the love will never get lost\n\nand when brotherhood come first then the line\nwill never be crossed established it on our own\nwhen that line had to be drawn and that line is what\nwe reach so remember me when i'm gone\n\nhow could we not talk about family when family's all that we got?\neverything i went through you were standing there by my side\nand now you gonna be with me for the last ride\nlet the light guide your way hold every memory\nas you go and every road you take will always lead you home\n\nhoo\n\nit's been a long day without you my friend\n\nand i'll tell you all about it when i see you again\n\nwe've come a long way from where we began\noh i'll tell you all about it when i see you again\nwhen i see you again\nagain\n\nwhen i see you again see you again\n\nwhen i see you again"
>>> s=s.lower()
>>> s.replace(',,?,!,.',' ') "it's been a long day without you my friend\n\nand i'll tell you all about it when i see you again\n\nwe've come a long way from where we began\noh i'll tell you all about it when i see you again\nwhen i see you again\n\ndamn who knew all the planes we flew\ngood things we've been through\nthat i'll be standing right here\ntalking to you about another path\ni know we loved to hit the road and laugh\nbut something told me that it wouldn't last\nhad to switch up look at things different see the bigger picture\nthose were the days hard work forever pays\nnow i see you in a better place\n\nhow could we not talk about family when family's all that we got?\neverything i went through you were standing there by my side\nand now you gonna be with me for the last ride\nit's been a long day without you my friend\n\nand i'll tell you all about it when i see you again\n\nwe've come a long way from where we began\noh i'll tell you all about it when i see you again\n\nwhen i see you again\n\nfirst you both go out your way\nand the vibe is feeling strong and what's\nsmall turn to a friendship a friendship\nturn into a bond and that bond will never\nbe broke and the love will never get lost\n\nand when brotherhood come first then the line\nwill never be crossed established it on our own\nwhen that line had to be drawn and that line is what\nwe reach so remember me when i'm gone\n\nhow could we not talk about family when family's all that we got?\neverything i went through you were standing there by my side\nand now you gonna be with me for the last ride\nlet the light guide your way hold every memory\nas you go and every road you take will always lead you home\n\nhoo\n\nit's been a long day without you my friend\n\nand i'll tell you all about it when i see you again\n\nwe've come a long way from where we began\noh i'll tell you all about it when i see you again\nwhen i see you again\nagain\n\nwhen i see you again see you again\n\nwhen i see you again">>> s.count('the') 15 >>> s.count('see') 14
2.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等>>> t=list('12223344')
-
>>> t ['1', '2', '2', '2', '3', '3', '4', '4']
#增
>>> t.append(5) >>> t ['1', '2', '2', '2', '3', '3', '4', '4', 5]
#改 >>> t.insert(1,5) >>> t ['1', 5, '2', '2', '2', '3', '3', '4', '4', 5] >>> type(t) <class 'list'>
#删 >>> t.pop(1) 5 >>> t
#查询 ['1', '2', '2', '2', '3', '3', '4', '4', 5]>>> t.index('3') 4 >>> t.count('3') 2 >>> t.count('1') 1 - 简要描述列表与元组的异同。 异:列表是可以添加,删除,或者是搜索列表中的项目。由于你可以增加或删除项目,也可变的数据类型,用过[]进行项目定义。元组不能修改项目和数据类型,它是通过()中用逗号分隔项目的定义。 同:列表和元组都可以嵌套
浙公网安备 33010602011771号