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

    1、

    d={'001':89,"002":68,"003":87,"004":76,"005":71,"006":92}
    print(d["001"])
    print("007" in d)
    print(d.keys())
    print(d.values())
    print(d.items())
    print(d.pop("001"))
    print(d.get("005","查无此人"))
    del(d["003"])
    print(d)

     2、列表,元组,字典,集合的遍历。

    ss=set("1234543")
    sa=set("3456")
    print(ss&sa)
    print(ss|sa)
    print(ss-sa)
    
    for i in ss:
        print(i,end='')
    print()
    
    lis=list("1234567")
    tu=tuple("dhrcnji")
    dt=dict(zip(lis,tu))
    
    for i in lis:
        print(i,end='')
    print()
    
    for i in tu:
        print(i,end='')
    print()
    
    for i in dt:
        print(i,dt[i])

    3、英文词频统计实例

    1. 待分析字符串
    2. 分解提取单词
      1. 大小写 txt.lower()
      2. 分隔符'.,:;?!-_’
      3. 单词列表
    3. 单词计数字典
    str='''We don't talk anymore
    We don't talk anymore
    We don't talk anymore
    Like we used to do 
    We don't laugh anymore
    What was all of it for? 
    We don't talk anymore 
    Like we used to do
    I just heard you found the one you've been lookin'
    The one you been looking for
    I wish i would've konwn that wasn't me 
    Cause even after all this time i still wonder
    Why i can't move on? 
    Just the way you dance so easliy 
    Don't wanna know 
    The kinda dress you're wearin' tonight
    If he's holdin' onto you so tight
    The way i did before
    I overdosed 
    Should've known your love was game
    Now I can't get'cha out of my brain
    Ooh it's such a shame
    We don't talk anymore
    We don't talk anymore 
    We don't talk anymore
    Like we used to do 
    We don't laugh anymore
    What was all of it for?
    We don't talk anymore 
    Like we used to do
    I just hope you'r lyin' next to somebody
    Know it's hard to love ya like me
    Must be a good reason that you're gone
    Every now and then
    I think you might want me to come show up your door
    But I'm just too afraid that i'll be worng
    Don't wanna know 
    If you'ra lookin' into her eyes
    If she's holdin' onto you so tight
    The way i did before
    I overdosed
    Should've know your love was a game 
    Now I can't get'cha out of my brain
    Ooh it's such a shame
    We don't talk anymore
    We don't talk anymore
    We don't talk anymore
    Like we used to do 
    We don't laugh anymore
    What was all of it for? 
    We don't talk anymore
    Like we used to do
    Like we used to do
    Don't wanna know
    The kinda dress you're wearin' tonight
    If he's givin' it to you just right
    The way i did before
    I overdosed
    Should've know your love was a game 
    Now I can't get'cha out of my brain
    Ooh it's such a shame
    We don't talk anymore
    We don't talk anymore
    We don't talk anymore
    Like we used to do 
    We don't laugh anymore
    What was all of it for? 
    We don't talk anymore
    Like we used to do
    We don't talk anymore
    The way did before
    We don't talk anymore
    Ooh 
    Woo
    Ooh it's such a shame
    We don't talk anymore
    '''
    for i in ",.?!
    ":
       str=str.replace(i," ")
    str=str.lower()
    str=str.split(" ")
    words=set(str)
    dt={}
    dt["we"]=str.count("we")
    dt["talk"]=str.count("talk")
    for i in words:
       dt[i]=str.count(i)
    
    for i in dt:
       print("{0:<10}{1}".format(i,dt[i]))

  • 相关阅读:
    C# 在RichTextBox根据内容自动调整高度
    C# TabControl 隐藏标签头(TabControl Hide Head)
    SQL Server Profiler的简单使用
    Entity Framework Code First 在Object Join Linq查询时出现全表查询的语句。
    传统if 从句子——以条件表达式作为if条件
    正向行为方法---解决问题
    Shell的特殊字符
    精进:如何成为一个很厉害的人---思维导图
    Linux下用于查看系统当前登录用户信息的4种方法
    有用户及目录判断的删除文件内容的Shell脚本
  • 原文地址:https://www.cnblogs.com/Naiky/p/7573257.html
Copyright © 2011-2022 走看看