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

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

    s='''You were the shadow to my light

    Did you feel us?

    Another star

    You fade away

    Afraid our aim is out of sight

    Wanna see us

    Alive

    Where are you now?

    Where are you now?

    Where are you now?

    Was it all in my fantasy?

    Where are you now?

    Were you only imaginary?

    Where are you now?

    Atlantis

    Under the sea

    Under the sea

    Where are you now?

    Another dream

    The monster's running wild inside of me

    I'm faded

    I'm faded

    So lost, I'm faded

    I'm faded

    So lost, I'm faded

    These shallow waters never met what I needed

    I'm letting go a deeper dive

    Eternal silence of the sea. I'm breathing alive

    Where are you now?

    Where are you now?

    Under the bright but faded lights

    You've set my heart on fire

    Where are you now?

    Where are you now?

    Where are you now?

    Atlantis

    Under the sea

    Under the sea

    Where are you now?

    Another dream

    The monster's running wild inside of me

    I'm faded

    I'm faded

    So lost, I'm faded

    I'm faded

    So lost, I'm faded
    '''
    s=s.lower()
    for i in',.?!':
    s=s.replace(i,' ')
    words=s.split(' ')
    print(s)

    print ('fade:{0}'.format(s.count('fade')))
    print ('faded:{0}'.format(s.count('faded')))
    print ('where are you now :{0}'.format(s.count('where are you now ')))

     

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

     

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

    元组用方括号[]赋值,用逗号隔开每一个元素,列表中的元素可以增删查改,还能改变元素的类型,元组用小括号()赋值,元组内的元素可供读取,但无法修改。

  • 相关阅读:
    转载JGTM' 2004[MVP]有关AOP的三篇精彩文章
    新增Skin
    发表文章的要求
    自定义UserControl的属性为什么不能在设计时显示在属性窗口中
    .Text学习笔记(一)
    访问类的private或internal成员[转载]
    博客园对发表文章的一些要求
    博客园成立了管理团队
    推荐一篇介绍.NET MetaData的文章
    让大家久等了:终于完成了AOP尝鲜系列之第三部[JGTM'2004 [MVP]文章转载]
  • 原文地址:https://www.cnblogs.com/GAODASHANG/p/7563142.html
Copyright © 2011-2022 走看看