• 9.20


    1. 实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
    news='''All the times that you rain on my parade
    And all the clubs you get in using my name
    You think you broke my heart
    Ohhh girl for goodness sake
    You think I'm crying
    Oh my ohhh, well I ain't!
    And I didn't wanna write a song
    'Cause I didn't want anyone thinking I still care, I don't
    But, you still hit my phone up
    And baby I be moving on
    And I think you should be somethin' I don't wanna hold back
    Maybe you should know that
    My mama don't like you and she like's everyone'''
    news=news.lower()
    for i in ',!':
        news=news.replace(i,' ')
    words=news.split(' ')
    print(words)
    print('you:',words.count('you'))
    print('and:',words.count('and'))

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

    pf=list('12321222132121213320')
    for i in range(len(pf)):
        pf[i]=int(pf[i])
    print(pf)
    print(pf.index(3))
    print(pf.count(1))
    print(pf.count(3))

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

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

  • 相关阅读:
    二分查找
    「数学」二次函数中项系数大小与图像的关系
    「数学」夹角公式
    「CF80A」Panoramix's Prediction
    「Luogu P6101」[EER2]出言不逊
    「数学」三角函数公式以及部分证明
    「Luogu P6069」[MdOI2020] Group
    「CF80B」Depression
    「数学」Menelaus定理与Ceva定理
    「AT1175」ニコニコ文字列
  • 原文地址:https://www.cnblogs.com/chenyanxi123/p/7562011.html
Copyright © 2020-2023  润新知