zoukankan      html  css  js  c++  java
  • 英文词频统计预备,组合数据类型练习

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

    song='''I don't like your little games
    Don't like your tilted stage
    The role you made me play of the fool
    No I don't like you
    I don't like your perfect crime
    How you laugh when you lie
    You said the gun was mine
    Isn't cool
    No I don't like you ooh
    But I got smarter I got harder in the nick of time
    Honey I rose up from the dead I do it all the time
    I got a list of names and yours is in red underlined
    I check it once then I check it twice ooh
    Ooh look what you made me do
    Look what you made me do
    Look what you just made me do
    Look what you just made me
    Ooh look what you made me do
    Look what you made me do
    Look what you just made me do
    Look what you just made me do
    I don't like your kingdom keys
    They once belonged to me
    You asked me for a place to sleep
    Locked me out and threw a feast what
    The world moves on another day another drama drama
    But not for me not for me all I think about is karma
    And then the world moves on but one thing's for sure
    Maybe I got mine but you'll all get yours
    But I got smarter I got harder in the nick of time
    Honey I rose up from the dead I do it all the time
    I've got a list of names and yours is in red underlined
    I check it once then I check it twice ooh
    Ooh look what you made me do
    Look what you made me do
    Look what you just made me do
    Look what you just made me
    Ooh look what you made me do
    Look what you made me do
    Look what you just made me do
    Look what you just made me do
    I don't trust nobody and nobody trusts me
    I'll be the actress starring in your bad dreams
    I don't trust nobody and nobody trusts me
    I'll be the actress starring in your bad dreams
    I don't trust nobody and nobody trusts me
    I'll be the actress starring in your bad dreams
    I don't trust nobody and nobody trusts me
    I'll be the actress starring in your bad dreams
    Look what you made me do
    Look what you made me do
    Look what you made me do
    I'm sorry the old Taylor can't come to the phone right now
    Why
    Oh 'cause she's dead ohh
    Ooh look what you made me do
    Look what you made me do
    Look what you just made me do
    Look what you just made me
    Ooh look what you made me do
    Look what you made me do
    Look what you just made me do
    Look what you just made me do
    Ooh look what you made me do
    Look what you made me do
    Look what you just made me do
    Look what you just made me
    Ooh look what you made me do
    Look what you made me do
    Look what you just made me do
    Look what you just made me do'''
    song=song.lower()
    song=song.replace('
    ',' ')
    word=song.split(' ')
    print ('look:{0}'.format(song.count('look')))
    print ('what:{0}'.format(song.count('what')))
    print ('you:{0}'.format(song.count('you')))
    print ('made:{0}'.format(song.count('made')))
    print ('me:{0}'.format(song.count('me')))
    print ('do:{0}'.format(song.count('do')))

    输出结果是:

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

    score=list('1233213231321')
    print(score)
    #增加一个2分的
    score=score.append('2')
    print(score)
    #删除最后一个
    score=score.pop()
    print(score)
    #修改第2个
    score[2]='1'
    print(score)
    #查询第3个
    print(score[3])
    #全部修改为数值型
    for i in range(len(score)):
        score[i]=int(score[i])
    #查询出第一个3分的下标
    print(score.index(3))
    #1分的同学有多少个,3分有多少个
    print(score.count(1))
    print(score.count(3))

     运行结果是:

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

    list是处理一组有序项目的数据结构,即你可以在一个列表中存储一个序列的项目。列表中的项目。列表中的项目应该包括在方括号中,这样python就知道你是在指明一个列表。元组通常用在使语句或用户定义的函数能够安全的采用一组值的时候,即被使用的元组的值不会改变。元组可以嵌套。

  • 相关阅读:
    Edit Distance编辑距离(NM tag)- sam/bam格式解读进阶
    《开讲啦》 20160910 颜宁:女科学家去哪儿了?
    pysam
    Python项目实战
    最小二乘估计法
    最大似然估计(Maximum Likelihood,ML)
    HMM隐马尔科夫模型
    贝叶斯推断|朴素贝叶斯分类|贝叶斯定理
    解决“tar:Exiting with failure status due to previous errors”【转】
    df -h执行卡住不动问题解决【转】
  • 原文地址:https://www.cnblogs.com/iamzhuangyuan/p/7562074.html
Copyright © 2011-2022 走看看