• 英文词频统计预备,组合数据类型练习


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

    s='''You were the shadow to my life Did you feel us Another start You fade away Afraid our aim is out of sight
     anna 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'''
    
    #将所有大写转换为小写
    s=s.lower()
    print('全部转换为小写:'+s+'
    ')
    
    #将所有将所有其他做分隔符(,.?!)替换为空格
    for i in ',.?!':
        s=s.replace(i,' ')
    print('其他分隔符替换为空格的结果:'+s+'
    ')
    
    #统计单词‘was’出现的次数
    count=s.count('was')
    print('单词was出现的次数为:',count)
    
    #分隔出一个一个单词
    s=s.split(' ')
    print('分隔结果为:',s)
    

      

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

    b=list('12321232123322')
    print('作业评分列表:',b)
    
    c=b.index('3')
    print('第一个3分的下标是:',c)
    
    d=b.count('1')
    print('1分的同学数量:',d)
    
    e=b.count('3')
    print('3分的同学数量:',d)
    

      

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

    列表是Python的一种内置数据类型,list是一种有序的集合,可以随时添加和删除其中的元素。

    元组与列表相似,只是tuple一旦定义了就不可修改

  • 相关阅读:
    MyMacro
    CConfigXmlFile02
    “十步一杀” 干掉你的职场压力
    只有聪明人才悟到:通向成功的饥饿法则
    高层管理者应具备什么样的特点? (转)
    两个小故事,告诉你不可不知的成功密码
    中秋望月
    锦里中秋有感
    支招:如何增强创业信心,克服创业恐惧?
    创业者必看:创业得出的10条血泪经验
  • 原文地址:https://www.cnblogs.com/0055sun/p/7574355.html
Copyright © 2020-2023  润新知