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

Posted 钟嘉丽

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了英文词频统计预备,组合数据类型练习相关的知识,希望对你有一定的参考价值。

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

    song=\'\'\'When I was dreaming about you baby
    You were dreaming of me
    Call me crazy
    Call me blind
    To still be suffering is stupid after all of this time
    Did I lose my love to someone better
    And does she love you like I do
    I do, you know I really really do
    Well hey
    So much I need to say
    Been lonely since the day
    The day you went away
    So sad but true
    For me there\'s only you
    Been crying since the day
    the day you went away
    I remember date and time
    September twenty second
    Sunday twenty five after nine
    In the doorway with your case
    No longer shouting at each other
    There were tears on our faces
    And we were letting go of something special
    Something we\'ll never have again
    I know, I guess I really really know
    Why do we never know what we\'ve got till it\'s gone
    How could I carry on the day you went away
    Cause I\'ve been missing you so much I have to say
    just one last dance\'\'\'
    songs=song.lower()
    song=song.replace(\',\',\' \')
    print(song)
    words=song.split(\' \')
    print(words)

  •  

  • 列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
    ls=list(\'12134165135241335363\')
    for i in range (len(ls)):
        ls[i]=int(ls[i])
    print(ls)
    print(ls.index(3))
    print(ls.count(1))
    print(ls.count(3))
  •  

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

以上是关于英文词频统计预备,组合数据类型练习的主要内容,如果未能解决你的问题,请参考以下文章

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

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

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

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

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

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