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

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

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

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

  • 相关阅读:
    C++高级程序员(廊坊+高薪)欢迎各种漂回家!(该职位已截止)
    utf8_unicode_ci和utf8_general_ci区别
    Percentencoding
    libiconv GNU Project Free Software Foundation (FSF)
    2013年1月6日北京交流会:当当网如何打造个性化推荐&精准营销生态系统
    COM Vs .NET (Qt ActiveQt)
    新一篇: Unicode字符编码规范 实例详细介绍各种字符集编码转换问题
    甩开外包,雄踞榜首:揭开“宫爆老奶奶”成功的秘密
    awk使用命令
    API SOCKET基础(三)网络字节序与主机字节序的转换
  • 原文地址:https://www.cnblogs.com/YyYyYy11/p/7562114.html
Copyright © 2011-2022 走看看