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、简要描述列表与元组的异同。

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

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

     
     
     
    好文要顶 关注我 收藏该文 
  • 相关阅读:
    225. Implement Stack using Queues
    232. Implement Queue using Stacks
    LeetCode 763 划分字母区间
    CentOS7+eDEX-UI打造属于你的极客桌面
    好玩又有趣的linux终端命令
    Linux 应急响应入门——入侵排查
    active_anon/inactive_anon
    Red Hat 平台的推荐交换大小是多少?
    为什么RHEL系统使用交换空间而不是释放缓存和缓冲内存?
    RHEL 交换内存(Swap)使用率为 100%
  • 原文地址:https://www.cnblogs.com/cch-1007/p/7565137.html
Copyright © 2011-2022 走看看