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

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

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

  • 相关阅读:
    文件上传
    data.push({name:'a',value:'a'});
    es数据迁移脚本(python)
    es修改数据类型
    SqlServer应用程序的高级Sql注入
    ASP.NET中如何防范SQL注入式攻击
    AJAX.NET框架构建Lookup服务器控件
    asp.net 读写 XML 小结
    Global.asax 文件
    ajaxpro.2.dll 简单应用
  • 原文地址:https://www.cnblogs.com/lintingting/p/7562071.html
Copyright © 2011-2022 走看看