zoukankan      html  css  js  c++  java
  • 字典

    d = {key1 : value1, key2 : value2 }

    键必须是唯一的,但值则不必。

    值可以取任何数据类型,但键必须是不可变的,如字符串,数字或元组。

    访问字典中的键

    dict1 = { 'abc': 456 }

    print dict1['abc']

    清空字典所有条目,删除字典中的键,删除字典

    dict1.clear()

    del dict1['abc']

    del dict1  

    字典去掉value,光保留key,叫做set,集合

    以下转载自https://www.cnblogs.com/whatisfantasy/p/5956775.html

    s = set()

    s = {11,22,33,44}  #注意在创建空集合的时候只能使用s=set(),因为s={}创建的是空字典

    a=set('boy')

    b=set(['y', 'b', 'o','o'])

    c=set({"k1":'v1','k2':'v2'})

    d={'k1','k2','k2'}

    e={('k1', 'k2','k2')}

    print(a,type(a))

    print(b,type(b))

    print(c,type(c))

    print(d,type(d))

    print(e,type(e))

    OUTPUT:

    {'o', 'b', 'y'} <class 'set'>

    {'o', 'b', 'y'} <class 'set'>

    {'k1', 'k2'} <class 'set'>

    {'k1', 'k2'} <class 'set'>

    {('k1', 'k2', 'k2')} <class 'set'>

  • 相关阅读:
    Evensgn 的债务
    Passward
    拯救莫莉斯
    文艺平衡树
    Fliptile 翻格子游戏
    Making the Grade (bzoj1592)
    紧急疏散evacuate
    Password
    [NOIP2015]斗地主
    运输问题1
  • 原文地址:https://www.cnblogs.com/saolv/p/8360996.html
Copyright © 2011-2022 走看看