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

    1. 实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
    2. 列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
    3. 简要描述列表与元组的异同

     1.

    b='''Myanmar's Aung San Suu Kyi is facing mounting international pressure for her handling of violence in Rakhine state and the Rohingya refugee crisis.
    In a speech on Tuesday, the de facto leader condemned rights abuses but did not blame the army or address allegations of ethnic cleansing.
    Leaders and diplomats from several countries have since expressed strong disappointment with her stance.
    More than 400,000 Rohingya have fled to Bangladesh since late August.
    The latest unrest in troubled Rakhine was sparked by deadly attacks on police stations across the state last month, blamed on a newly emerged militant group, the Arakan Rohingya Salvation Army (Arsa).
    Scores of people were killed in an ensuing military crackdown and there are widespread allegations of villages being burned and Rohingya being driven out.'''
    b.lower()
    for i in ',.?-_':
        b=b.replace(i,' ')
    words=b.split()
    print(words)
    print ('did:{0}'.format(b.count('did')))
    print ('a:{0}'.format(b.count('a')))
    print ('have:{0}'.format(b.count('have')))
    print ('people:{0}'.format(b.count('people')))
    

      

    结果:  

    ["Myanmar's", 'Aung', 'San', 'Suu', 'Kyi', 'is', 'facing', 'mounting', 'international', 'pressure', 'for', 'her', 'handling', 'of', 'violence', 'in', 'Rakhine', 'state', 'and', 'the', 'Rohingya', 'refugee', 'crisis', 'In', 'a', 'speech', 'on', 'Tuesday', 'the', 'de', 'facto', 'leader', 'condemned', 'rights', 'abuses', 'but', 'did', 'not', 'blame', 'the', 'army', 'or', 'address', 'allegations', 'of', 'ethnic', 'cleansing', 'Leaders', 'and', 'diplomats', 'from', 'several', 'countries', 'have', 'since', 'expressed', 'strong', 'disappointment', 'with', 'her', 'stance', 'More', 'than', '400', '000', 'Rohingya', 'have', 'fled', 'to', 'Bangladesh', 'since', 'late', 'August', 'The', 'latest', 'unrest', 'in', 'troubled', 'Rakhine', 'was', 'sparked', 'by', 'deadly', 'attacks', 'on', 'police', 'stations', 'across', 'the', 'state', 'last', 'month', 'blamed', 'on', 'a', 'newly', 'emerged', 'militant', 'group', 'the', 'Arakan', 'Rohingya', 'Salvation', 'Army', '(Arsa)', 'Scores', 'of', 'people', 'were', 'killed', 'in', 'an', 'ensuing', 'military', 'crackdown', 'and', 'there', 'are', 'widespread', 'allegations', 'of', 'villages', 'being', 'burned', 'and', 'Rohingya', 'being', 'driven', 'out']
    did:1
    a:66
    have:2
    people:1

    grades=list('25413431')
    grades.append('2')
    print(grades)
    
    grades.pop()
    print(grades)
    
    grades[1] = '5'
    print(grades)


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


    ['2', '5', '4', '1', '3', '4', '3', '1', '2']
    >>> grades=list('25413431')
    >>> grades.append('2')
    >>> print(grades)
    ['2', '5', '4', '1', '3', '4', '3', '1', '2']
    >>> grades.pop()
    '2'
    >>> print(grades)
    ['2', '5', '4', '1', '3', '4', '3', '1']
    >>> grades[1] = 5
    >>> print(grades)
    ['2', 5, '4', '1', '3', '4', '3', '1']
    >>> grades[1]='5'
    >>> print(grades)
    ['2', '5', '4', '1', '3', '4', '3', '1']

    3

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

    元组一旦初始化就不能改变里面的元素,而列表可以。

    列表中的项目应该包括在方括号中,元组在圆括号中
    你可以增删改或是搜索列表中的项目。

  • 相关阅读:
    基于session做的权限控制
    spring有关jar包的作用
    Failed to apply plugin [id 'com.android.application'] 和 Could not find com.android.tools.build:gradle:2.XX的最正确的解决方法
    Android Handler机制(四)---Handler源码解析
    System.currentTimeMillis()与SystemClock.uptimeMillis()
    【转】博客美化(6)为你的博文自动添加目录
    Android Handler机制(三)----Looper源码解析
    Android Handler机制(二)---MessageQueue源码解析
    Android Handler机制(一)---Message源码分析
    关于Android Force Close 出现的原因 以及解决方法
  • 原文地址:https://www.cnblogs.com/YyYyYy11/p/7562114.html
Copyright © 2011-2022 走看看