• 组合数据类型练习,英文词频统计实例上


    1.字典实例:建立学生学号成绩字典,做增删改查遍历操作。

    d={'001':'90','002':'80','003':'75','004':'65','005':'85'}
    print(d.get('001'))
    d.pop('002')
    d['003']=65
    for i in d:
        print(i)

     

    2.

    列表,元组,字典,集合的遍历。
    总结列表,元组,字典,集合的联系与区别。

    复制代码
    l=list('12345678')
    print('遍历列表:')
    for i in l:
        print(i)
    t=tuple('abcdefg')
    print('遍历元组:')
    for i in t:
        print(i)
    d={'001':50,'002':90,'003':85}
    print('遍历字典:')
    for i in d:
        print(i,d[i])
    s=set(l)
    print('遍历集合:')
    for i in s:
        print(i)
    复制代码

    1.列表是任意对象的序列,用方括号表示。

    2.将一组值打包到一个对象中,称为元组。元组用圆括号表示.元组和列表的大部分操作相同。但是,列表是不固定的,可以随时插入,删除;而元组一旦确认就不能够再更改。所以,系统为了列表的灵活性,就需要牺牲掉一些内存;而元组就更为紧凑。

    3.集合是无序的,也不能通过索引进行访问且集合中的元素不能重复。

    4.字典就是一个关联数组或散列表,其中包含通过关键字索引的对象。用大括号表示。与集合相比,通过关键字索引,所以比集合访问方便。

    3.英文词频统计实例

    A.待分析字符串

    B.分解提取单词
    a.大小写 txt.lower()
    b.分隔符'.,:;?!-_’
    c.单词列表
    C.单词计数字典

    复制代码
    s='''You were my everythingthis goes out to someone that was 
    once the most important person in my life 
    i didn't realize it at the time 
    i can't forgive myself for the way i treated you so 
    i don't really expect you to either 
    it's just... i don't even know 
    just listen... 
    you're the one that i want, the one that i need 
    the one that i gotta have just to succeed '''
    s=s.lower()
    for i in ',':
        s=s.replace(i,' ')
    w=s.split(' ')
    print(w)
    dict={}
    for i in w:
        dict[i]=w.count(i)
    print(dict)
    复制代码

  • 相关阅读:
    inet_ntoa 的一个小问题
    获取DNS服务器的版本信息
    host_network_interfaces_slow_mode_thresholds
    10月8日至11月底考试安排
    腾讯广点通防作弊
    移动广告作弊方式及防范方式
    广告联盟常用的防作弊手续
    移动端点击作弊与激活作弊的现象与预警
    数据科学家最常用的十种算法(我准备拿这个当成学习参考)
    项目的命名规范,为以后的程序开发中养成良好的行为习惯
  • 原文地址:https://www.cnblogs.com/cch-1007/p/7573311.html
Copyright © 2020-2023  润新知