首页 > 其他 > 详细

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

时间:2017-09-22 22:17:28      阅读:290      评论:0      收藏:0      [点我收藏+]
  1. 实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
    a = ‘‘‘God Is A Girl
    Remembering me, 
    Discover and see 
    All over the world, 
    She‘s known as a girl 
    To those who a free, 
    The mind shall be key 
    Forgotten as the past 
    ‘Cause history will last 
    God is a girl, 
    Wherever you are, 
    Do you believe it, can you recieve it? 
    God is a girl, 
    Whatever you say, 
    Do you believe it, can you recieve it? 
    God is a girl, 
    However you live, 
    Do you believe it, can you recieve it? 
    God is a girl, 
    She‘s only a girl, 
    Do you believe it, can you recieve it? 
    She wants to shine, 
    Forever in time, 
    She is so driven, she‘s always mine 
    Cleanly and free, 
    She wants you to be 
    A part of the future, 
    A girl like me 
    There is a sky, 
    Illuminating us, someone is out there 
    That we truly trust 
    There is a rainbow for you and me 
    A beautiful sunrise ete‘‘‘
    a =a.lower()
    print(god出现次数为:+str(a.count(god)))
    for i in ,,?,!:
        a=a.replace(i, )
    a=a.split( )
    print(a)

     技术分享

     

  2. 列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
    grade=list(12312133212321)
    grade=[int(x) for x in grade]
    print(成绩表:,grade)
    
    grade.insert(0,2)
    print(开始增加分值为2的分数,grade)
    grade.pop(0)
    print(删除增加的分数,grade)
    print(输出第一个3分的同学的下标:,grade.index(3))
    print(统计1分的同学人数:,grade.count(1))
    
    print(统计3分的同学人数:,grade.count(3))

    技术分享

     

  3. 简要描述列表与元组的异同。                                                                           
  4. 列表是可变的数据类型,用方括号显示。元组是不可变的 ,用圆括号显示。两者都可以嵌套。   

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

原文:http://www.cnblogs.com/xy123ing/p/7577067.html

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