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

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

    news=('''When I was young I'd listen to the radio
    Waiting for my favorite songs
    When they played I'd sing along,
    It make me smile.

    Those were such happy times and not so long ago
    How I wondered where they'd gone.
    But they're back again just like a long lost friend
    All the songs I love so well.
    Every shalala every wo'wo
    still shines.

    Every shing-a-ling-a-ling that they're starting to sing
    so fine

    When they get to the part
    where he's breaking her heart
    It can really make me cry
    just like before.
    It's yesterday once more.
    (Shoobie do lang lang)
    (Shoobie do lang lang)
    Looking bak on how it was in years gone by
    And the good times that had
    makes today seem rather sad,
    So much has changed.''')
    news=news.lower()
    for i in ',./':
    news=news.replace(i,' ')
    words=news.split(' ')
    print(news)
    print(news.count('lang'))
    print(news.split(' '))

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

    grade=list('12323112333')
    print(grade)
    for i in range(len(grade)):
    grade[i]=int(grade[i])
    print(grade)
    print(grade.index(3))
    print(grade.count(1))
    print(grade.count(3))

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

    列表中的项目应该包括在方括号中,
    你可以添加、删除或是搜索列表中的项目。
    由于你可以增加或删除项目,所以列表是可变的数据类型,
    即这种类型是可以被改变的。

    元组和列表十分类似,但是元组是不可变的.
    也就是说你不能修改元组。
    元组通过圆括号中用逗号分割的项目定义。
    元组通常用在使语句或用户定义的函数能够安全地采用一组值的时候,
    即被使用的元组的值不会改变。

  • 相关阅读:
    从零实现一个功能完善的迷你区块链
    Merkle Tree理解起来并不难
    微信、支付宝个人收款的一种实现思路
    PostgreSQL的登录、创建用户、数据库并赋权
    java list 按照多字段排序
    2019年最新全国省市区街道共46462条数据(统计局MySQL数据库)
    一份非常值得一看的Java面试题
    spring scope prototype与singleton
    http请求与响应,TCP三次握手&四次分手
    HTTP协议三次握手过程
  • 原文地址:https://www.cnblogs.com/lintingting/p/7562071.html
Copyright © 2011-2022 走看看