zoukankan      html  css  js  c++  java
  • 016_dict

    #!/usr/bin/env python
    # Author:liujun

    info = {
    'stu1101':"TenglanWu",
    'stu1102':"LongzaLuola",
    'stu1103':"XiaoZeMaliya",
    'stu1104':"TenglanWu",
    'stu1105':"LongzaLuola",
    'stu1106':"TenglanWu",
    'stu1107':"LongzaLuola",
    'stu1108':"TenglanWu",
    'stu1109':"LongzaLuola",
    'stu1110':"TenglanWu",
    'stu1111':"LongzaLuola",
    }


    print(info["stu1101"])
    # an error ocurred if it doesn't exist.
    print(info.get('stu1103'))
    # return null if it doesn't exist.
    print('stu1104' in info)
    # Determine if it exists.



    info["stu1101"] = "canglaoshi"
    # Modify if it exists,otherwise create a new element.




    del info["stu1101"]
    info.pop("stu1102") # At least one arguments is given
    # delete an element
    info.popitem()
    # Randomly delete an element




    av_catalog = {
    "Am":{
    "www.youporn.com": ["很多免费的,世界最大的","质量一般"],
    "www.pornhub.com": ["很多免费的,也很大","质量比yourporn高点"],
    "letmedothistoyou.com": ["多是自拍,高质量图片很多","资源不多,更新慢"],
    "x-art.com":["质量很高,真的很高","全部收费,屌比请绕过"]
    },
    "japan":{
    "tokyo-hot":["质量怎样不清楚,个人已经不喜欢日韩范了","听说是收费的"]
    },
    "china":{
    "1024":["全部免费,真好,好人一生平安","服务器在国外,"]
    }
    }
    av_catalog["china"]["1024"][1] = "The web is in abroad"

    print(info.keys())
    # Print all keys
    print(info.values())
    # Print all values
    print(info.items())


    av_catalog.setdefault("taiwan",{"WWW.baidu.com":[1,2]})
    av_catalog.setdefault("china",{"1025":["xxxxxxxxxxxxx","ppppppppppppppppp"]})
    # Create a new element if it doesn't exist,otherwise return its value.

    av_catalog.update(info)
    print(av_catalog)



    for i in info: # recommanded
    print(i,info[i])
    for k,v in info.items():
    print(k,v)
  • 相关阅读:
    CodeForces 722C 题解
    ubuntu自带神奇文本编辑器-gedit使用入门
    My new Blog on cnblogs
    kaldi语音识别技术
    BUAA-OO-第三单元作业-JML之图论
    C++面向对象编程思想
    软件工程-设计模式
    BUAA-OO-第二单元作业-电梯调度
    操作系统make命令与Makefile文件编写
    操作系统启动过程分析(Linux-OS启动优化)
  • 原文地址:https://www.cnblogs.com/liujun5319/p/9588532.html
Copyright © 2011-2022 走看看