zoukankan      html  css  js  c++  java
  • 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.简要描述列表与元组的异同。

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

  • 相关阅读:
    Hadoop学习之安装HDFS
    常见的6种数据结构
    maven 编译出错 Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean
    jquery解决js对象、数组赋值时的引用传递
    405 method not allowed(方法不被允许)
    身份证件号 正确性检查方法
    svn 提交信息模板
    idea 使用说明
    java-System类
    java-Integer 类
  • 原文地址:https://www.cnblogs.com/chenyanxi123/p/7562011.html
Copyright © 2011-2022 走看看