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

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

    s='''Hey Jude, don't make it bad.
    Take a sad song and make it better.
    Remember to let her into your heart,
    Then you can start to make it better.
    Hey Jude, don't be afraid.
    You were made to go out and get her.
    The minute you let her under your skin,
    
    Then you begin to make it better.
    And anytime you feel the pain, hey Jude, refrain,
    Don't carry the world upon your shoulders.
    For well you know that it's a fool who plays it cool
    By making his world a little colder.
    Hey Jude, don't let me down.
    You have found her, now go and get her.
    Remember to let her into your heart,
    Then you can start to make it better.
    So let it out and let it in, hey Jude, begin,
    You're waiting for someone to perform with.
    And don't you know that it's just you, hey Jude, you'll do,
    The movement you need is on your shoulder.
    Hey Jude, don't make it bad.
    Take a sad song and make it better.
    Remember to let her under your skin,
    Then you'll begin to make it
    Better better better better better better, oh.
    Na na na, na na na na, na na na, hey Jude
    Na na na, na na na na, na na na, hey Jude
    Na na na, na na na na, na na na, hey Jude'''
    s.lower
    s.count('na')
    s.replace(',',' ')
    s.split(' ')

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

    >>>score=list('123212221333')
    ['1', '2', '3', '2', '1', '2', '2', '2', '1', '3', '3', '3']
    >>>print(score.index('3'))
    2
    >>>for i in range(len(score)):
        score[i]=int(score[i])
    >>> score
    [1, 2, 3, 2, 1, 2, 2, 2, 1, 3, 3, 3]
    >>> print(score.count('1'))
    0
    >>> print(score.count(1))
    3
    >>> print(score.count(3))
    4
    >>> score[0]='2'
    >>> print(score)
    ['2', 2, 3, 2, 1, 2, 2, 2, 1, 3, 3, 3]

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

    元组是不可变的,不可以进行添加、删除或修改,形式(1,2,3)

    列表是可变的,可以进行添加、查询或修改的操作,形式[1,2,3]

  • 相关阅读:
    C语言提供的位运算符
    JAVA反射改动常量,以及其局限
    直击中关村创业大街,新街头霸王来了
    bind() to 0.0.0.0:80 failed (98: Address already in use)
    Eclipse 快捷方式 指定 固定 workspace
    C++对象模型——Inline Functions(第四章)
    eclipse中安装freemarker插件及ftl使用freemarker编辑器
    迷茫了好一阵决定做WEB前端
    ios代理的使用,正向传值,逆向传值
    easyUI Tab href,content差别
  • 原文地址:https://www.cnblogs.com/hxl316/p/7574087.html
Copyright © 2011-2022 走看看