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

    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一旦定义了就不可修改

  • 相关阅读:
    javascript数据类型转换
    javascript运算符
    数据类型
    第一个JavaScript代码
    Javascript简介
    z-index
    Java代码优化
    Java中,什么是构造函数?什么是构造函数重载?什么是复制构造函数?
    java中继承条件下构造方法的执行过程
    java中的继承、重载和覆盖是什么意思
  • 原文地址:https://www.cnblogs.com/0055sun/p/7574355.html
Copyright © 2011-2022 走看看