英语词频统计预备、组合数据类型

本文通过具体的实例展示了如何进行文本预处理,包括转换大小写、去除特殊字符及统计单词频率等操作,并演示了使用Python列表进行数据管理的方法。
  1. 实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
    lp='''You hid your skeletons, when I had shown you mine
    you woke the devil that I thought you left behind
    I saw the evidence the crimson soaking through
    ten thousand promises, ten thousand ways to lose...
    
    And you held It all
    but you were careless to let it fall
    you held it all
    and I was by your side
    Powerless
    
    I watched you fall apart
    and chased you to the end
    I'm left an empty mess, that words can not defend
    you'll never know what I became
    because of you
    ten thousand promises, ten thousand ways to lose...
    
    And you held It all
    but you were careless to let it fall'''
    print(lp.lower())
    print(lp.replace(',',' '))
    print(lp.count("you"))
    print(lp.split(" "))

     

    
    

     

  2. 列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
    hw=list("123321222")
    print(hw)
    
    hw.append("1")
    print("增加:",hw)
    
    hw.insert(2,"1")
    print("插入:",hw)
    
    hw.pop()
    print("删除:",hw)
    
    hw[5]=2
    print('更改:',hw)
    
    print("第一个3分的下标:",hw.index("3"))
    print("1分的同学共有",hw.count("1"),"")
    print("3分的同学共有",hw.count("3"),"")

     

    
    

     

  3. 简要描述列表与元组的异同。
    list与turple一样,都是处理一组有序项目的数据结构。列表应该包括在方括号中,我们可以在一个列表中添加,删除,或者是查询,即列表的值是可以改变的。元组的值则是不能改变,元组包括在圆括号里。

转载于:https://www.cnblogs.com/yin-yeah/p/7574114.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值