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

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

    s=('''I'm a big, big girl
    in a big, big world
    It's not a big,big thing if you leave me
    But I do, do feel
    that I do, do will
    miss you much
    Miss you much

    I can see the first leaf falling
    It's all yellow and nice
    It's so very cold outside
    Like the way I'm feeling inside

    I'm a big, big girl
    in a big big world
    It's not a big, big thing if you leave me
    But I do, do feel
    that I do, do will
    miss you much
    Miss you much

    Outside it's now raining
    And tears are falling from my eyes
    Why did it have to happen
    Why did it all have to end

    I'm a big, big girl
    in a big, big world
    It's not a big, big thing if you leave me
    But I do, do feel
    that I do, do will
    miss you much
    Miss you much

    I have your arms around me
    Warm like fire
    But when I open my eyes
    You're gone

    I'm a big, big girl
    in a big, big world
    It's not a big, big thing if you leave me
    But I do, do feel
    that I do, do will
    miss you much
    Miss you much

    I'm a big, big girl
    in a big, big world
    It's not a big, big thing if you leave me
    But I do feel I will
    miss you much
    Miss you much''')

    s=s.lower()
    for i in ',':
    s=s.replace(i,' ')
    words=s.split(' ')
    print(s)
    print(s.lower())
    print(s.count('big'))
    print(s.split(' '))

    结果:

    i'm a big big girl
    in a big big world
    it's not a big big thing if you leave me
    but i do do feel
    that i do do will
    miss you much
    miss you much

    i can see the first leaf falling
    it's all yellow and nice
    it's so very cold outside
    like the way i'm feeling inside

    i'm a big big girl
    in a big big world
    it's not a big big thing if you leave me
    but i do do feel
    that i do do will
    miss you much
    miss you much

    outside it's now raining
    and tears are falling from my eyes
    why did it have to happen
    why did it all have to end

    i'm a big big girl
    in a big big world
    it's not a big big thing if you leave me
    but i do do feel
    that i do do will
    miss you much
    miss you much

    i have your arms around me
    warm like fire
    but when i open my eyes
    you're gone

    i'm a big big girl
    in a big big world
    it's not a big big thing if you leave me
    but i do do feel
    that i do do will
    miss you much
    miss you much

    i'm a big big girl
    in a big big world
    it's not a big big thing if you leave me
    but i do feel i will
    miss you much
    miss you much
    i'm a big big girl
    in a big big world
    it's not a big big thing if you leave me
    but i do do feel
    that i do do will
    miss you much
    miss you much

    i can see the first leaf falling
    it's all yellow and nice
    it's so very cold outside
    like the way i'm feeling inside

    i'm a big big girl
    in a big big world
    it's not a big big thing if you leave me
    but i do do feel
    that i do do will
    miss you much
    miss you much

    outside it's now raining
    and tears are falling from my eyes
    why did it have to happen
    why did it all have to end

    i'm a big big girl
    in a big big world
    it's not a big big thing if you leave me
    but i do do feel
    that i do do will
    miss you much
    miss you much

    i have your arms around me
    warm like fire
    but when i open my eyes
    you're gone

    i'm a big big girl
    in a big big world
    it's not a big big thing if you leave me
    but i do do feel
    that i do do will
    miss you much
    miss you much

    i'm a big big girl
    in a big big world
    it's not a big big thing if you leave me
    but i do feel i will
    miss you much
    miss you much
    30
    ["i'm", 'a', 'big', '', 'big', 'girl in', 'a', 'big', '', 'big', "world it's", 'not', 'a', 'big', 'big', 'thing', 'if', 'you', 'leave', 'me but', 'i', 'do', '', 'do', 'feel that', 'i', 'do', '', 'do', 'will miss', 'you', 'much miss', 'you', 'much i', 'can', 'see', 'the', 'first', 'leaf', "falling it's", 'all', 'yellow', 'and', "nice it's", 'so', 'very', 'cold', 'outside like', 'the', 'way', "i'm", 'feeling', "inside i'm", 'a', 'big', '', 'big', 'girl in', 'a', 'big', 'big', "world it's", 'not', 'a', 'big', '', 'big', 'thing', 'if', 'you', 'leave', 'me but', 'i', 'do', '', 'do', 'feel that', 'i', 'do', '', 'do', 'will miss', 'you', 'much miss', 'you', 'much outside', "it's", 'now', 'raining and', 'tears', 'are', 'falling', 'from', 'my', 'eyes why', 'did', 'it', 'have', 'to', 'happen why', 'did', 'it', 'all', 'have', 'to', "end i'm", 'a', 'big', '', 'big', 'girl in', 'a', 'big', '', 'big', "world it's", 'not', 'a', 'big', '', 'big', 'thing', 'if', 'you', 'leave', 'me but', 'i', 'do', '', 'do', 'feel that', 'i', 'do', '', 'do', 'will miss', 'you', 'much miss', 'you', 'much i', 'have', 'your', 'arms', 'around', 'me warm', 'like', 'fire but', 'when', 'i', 'open', 'my', "eyes you're", "gone i'm", 'a', 'big', '', 'big', 'girl in', 'a', 'big', '', 'big', "world it's", 'not', 'a', 'big', '', 'big', 'thing', 'if', 'you', 'leave', 'me but', 'i', 'do', '', 'do', 'feel that', 'i', 'do', '', 'do', 'will miss', 'you', 'much miss', 'you', "much i'm", 'a', 'big', '', 'big', 'girl in', 'a', 'big', '', 'big', "world it's", 'not', 'a', 'big', '', 'big', 'thing', 'if', 'you', 'leave', 'me but', 'i', 'do', 'feel', 'i', 'will miss', 'you', 'much miss', 'you', 'much']
    >>>

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

    >>> grades=list('123321123')
    >>> print(grades)
    ['1', '2', '3', '3', '2', '1', '1', '2', '3']
    >>> grades.pop(2)
    '3'
    >>> print(grades)
    ['1', '2', '3', '2', '1', '1', '2', '3']
    >>> grades[1]=grades[4]
    >>> print(grades)
    ['1', '1', '3', '2', '1', '1', '2', '3']
    >>> grades.index(3)

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

    list是一种有序的集合,可以随时添加和删除其中的元素。
    tuple和list非常类似,但是tuple一旦初始化就不能修改。
  • 相关阅读:
    (WPF)实现DataGrid中当某一列的值显示为密码样式
    利用双栈实现撤销与恢复逻辑
    WPF 中ContextMenu 在mvvm模式中的绑定问题
    WPF使用StringFormat绑定
    不注册调用COM组件
    再谈WPF绑定
    WPF的动态资源和静态资源
    MDI窗体(Winform)
    mysql 查询json字符串中符合条件的值
    phpstudy 导入sql到phpmyadmin中sql过大导致失败解决办法
  • 原文地址:https://www.cnblogs.com/xiaojiaqi/p/7562066.html
Copyright © 2011-2022 走看看