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

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

    sorry='''You gotta go and get angry at all of my honesty
    You know I try but I don’t do too well with apologies
    I hope I don’t run out of time, could someone call a referee?
    Cause I just need one more shot at forgiveness
    I know you know that I made those mistakes maybe once or twice
    By once or twice I mean maybe a couple a hundred times
    So let me, oh let me redeem, oh redeem, oh myself tonight
    Cause I just need one more shot at second chances
    Yeah, is it too late now to say sorry?
    Cause I’m missing more than just your body
    Is it too late now to say sorry?
    Yeah I know that I let you down
    Is it too late to say I’m sorry now?
    I’m sorry, yeah
    Sorry, yeah
    Sorry
    Yeah I know that I let you down
    Is it too late to say sorry now?
    I’ll take every single piece of the blame if you want me to
    But you know that there is no innocent one in this game for two
    I’ll go, I’ll go and then you go, you go out and spill the truth
    Can we both say the words and forget this?
    Is it too late now to say sorry?
    Cause I’m missing more than just your body
    Is it too late now to say sorry?
    Yeah I know that I let you down
    Is it too late to say I’m sorry now?
    I’m not just trying to get you back on me
    Cause I’m missing more than just your body
    Is it too late now to say sorry?
    Yeah I know that I let you down
    Is it too late to say sorry now?
    I’m sorry, yeah
    Sorry, oh
    Sorry
    Yeah I know that I let you down
    Is it too late to say sorry now?
    I’m sorry, yeah
    Sorry, oh
    Sorry
    Yeah I know that I let you down
    Is it too late to say sorry now?'''
    sorry=sorry.lower()#首字母小写
    for i in ',?':
        sorry=sorry.replace(i,' ')#替换所有的,?
    word=sorry.split(' ')#以‘ ’断开分成单独的字符串
    print(word)
    print('sorry:',word.count('sorry'))
    print('now:',word.count('now'))
    print('say:',word.count('say'))

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

    pf=list('12321222132121213320')#由字符串创建一个作业评分列表
    for i in range(len(pf)):
        pf[i]=int(pf[i])#字符串转化为整形
    print(pf)#输出整型评分表
    print(pf.index(3))#查询第一个3分的下标
    print(pf.count(1))#统计1分的同学个数
    print(pf.count(3))#统计3分的同学个数

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

    列表和元组非常类似,有时候他们都干一样的事情。他们最大的区别是元组一旦被赋值,值不可以被改变,一旦改变就会出错;但是列表可以任意的更改。其次的区别是他们用不同的符号表示,复制的时候,列表用方括号[],而元组用小括号()。

  • 相关阅读:
    解决子元素浮动,父元素高度变小的问题
    解决子元素设置margintop,效果到父元素上的问题
    应用部署时自动推送企业微信提醒
    自定义Gradle Task实现一键批量部署Springboot应用
    springboot中@PostConstruct、CommandLineRunner、BeanPostProcessor执行顺序
    win7 关闭防火墙
    Android 4.1模拟器访问服务器接口
    Android开发教程 葵花宝典第一层 初识Android
    Android开发教程 葵花宝典第四层 控件之 Toast Spinner RadioButton
    Android开发教程 葵花宝典第三层 控件之 Button CheckBox EditText TextView
  • 原文地址:https://www.cnblogs.com/liminghui3/p/7563090.html
Copyright © 2011-2022 走看看