首页 > 其他 > 详细

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

时间:2017-09-22 18:52:31      阅读:284      评论:0      收藏:0      [点我收藏+]
  1. 实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
    s=‘‘‘Twinkle, twinkle, little star,
    How I wonder what you are. 
    Up above the world so high, 
    Like a diamond in the sky. 
    When the blazing sun is gone, 
    When he nothing shines upon, 
    Then you show your little light, 
    Twinkle, twinkle, all the night. 
    Then the traveller in the dark, 
    Thanks you for your tiny spark, 
    He could not see which way to go, 
    If you did not twinkle so. 
    In the dark blue sky you keep, 
    And often through my curtains peep, 
    For you never shut your eye, 
    Till the sun is in the sky. 
    As your bright and tiny spark, 
    Lights the traveller in the dark. 
    Though I know not what you are, 
    Twinkle, twinkle, little star. ‘‘‘
    s=s.lower()
    s=s.replace(,, )
    s=s.replace(., )
    s=s.replace(?, )
    s=s.replace(!, )
    words=s.split( )
    print(words)
    print("little出现的次数为:"+str(words.count("little")))
    print("twinkle出现的次数为:"+str(words.count("twinkle")))

    技术分享

     

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

    s=list(1211331131323)
    print(列表:,s)
    print(列表长度:,len(s))
    
    s=[int(b) for b in s]
    print(更改为数值型:,s)
    
    s.append(3)
    s.insert(5,2)
    print(增加后列表:,s)
    
    s.pop()
    s.pop(3)
    print(删除后列表:,s)
    
    print(第一个3分的下标:,s.index(3))
    print(1分的同学人数:,s.count(1))
    print(3分的同学人数:,s.count(3))

    技术分享

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

              答:异:列表是用[ ]表示,元组是用()表示的;  创建了一个列表,你就可以添加,删除,或者是搜索列表中的项目。由于你可以增加或删除项目,我们说列表是可变的数据类型,即这种类型是可以被改变的。而元组通常用在使语句或用户定义的函数能够安全的采用一组值的时候,即被使用的元组的值不会改变。

                    同:列表和元组都是可以嵌套的。

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

原文:http://www.cnblogs.com/qisq/p/7574115.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!