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

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

    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 eternally

    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?'''

    girl=girl.lower()

    for i in ',?':    

         girl=girl.replace(i,' ')

    words=girl.split(' ')

    print(words)

    print('girl:',girl.count('girl'))

    print('a:',girl.count('a'))

    print('it:',girl.count('it'))

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

    marksheet=list('1234567')
    for i in range(len(marksheet)):
        marksheet[i]=int(marksheet[i])
    print(marksheet)
    marksheet.append(7)
    print(marksheet)
    marksheet.insert(2,'you')
    print(marksheet)
    print(marksheet.index(3))
    print(marksheet.count(1))
    print(marksheet.count(3))

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

    答:list
    序列是一种有序的序列,正向递增,反向递减序号,处理一组有序项目的数据结构,即你可以在一个列表中存储一个序列的项目。
    可以添加,删除,或者是搜索列表中的项目。由于你可以增加或删除项目,我们说列表是可变的数据类型,即这种类型是可以被改变的。列表是可以嵌套的。
    没有长度限制、元素类型可以不同。
       元组
    元祖和列表十分相似,不过元组是不可变的。即你不能修改元组。元组通过圆括号中用逗号分隔的项目定义。
    元组通常用在使语句或用户定义的函数能够安全的采用一组值的时候,即被使用的元组的值不会改变。元组可以嵌套
  • 相关阅读:
    小知识
    对NSArray中自定义的对象进行排序
    照片浏览滑动效果UIScrollView和UIPageControl组合
    label 设置行间距 字间距
    即使通讯聊天界面搭建----iOS
    ios8推送新增
    UITableviewCell滑动出现多级的控制按钮
    iOS 去掉html标签 留下原本的字符串
    平时常用的小知识点 (不断更新中)
    IOS UI多线程 NSThread 下载并显示图片到UIImageView
  • 原文地址:https://www.cnblogs.com/laidaili/p/7562053.html
Copyright © 2011-2022 走看看