• 字典|字典和数组嵌套|keys()|value()|item()|del


    python 中没有i++!

     1 dic = {
     2     'a':5,
     3     'kelv':'ooo',
     4     5:2333,
     5     2333:'yoo'
     6     }
     7 print dic[dic[dic['a']]]
     8 print dic
     9 
    10 #yoo
    11 #{'a': 5, 'kelv': 'ooo', 5: 2333, 2333: 'yoo'}
    12 
    13 dic['sss']='ooooppppp'
    14 print dic
    15 #{'a': 5, 'kelv': 'ooo', 5: 2333, 'sss': 'ooooppppp', 2333: 'yoo'}
    16 
    17 step=0
    18 dic ['b']=5
    19 for key,value in sorted(dic.items()):
    20     print key,"	",value
    21     step=step+1
    22 print "step is "+str(step)
    23 
    24 '''
    25 5       2333
    26 2333    yoo
    27 b       5
    28 a       5
    29 kelv    ooo
    30 sss     ooooppppp
    31 '''
    32 
    33 del dic['kelv']
    34 print dic
    35 
    36 #{'a': 5, 'b': 5, 5: 2333, 'sss': 'ooooppppp', 2333: 'yoo'}
    37 
    38 
    39 for k in set(dic.values()):
    40     print k
    41 
    42 '''
    43 5
    44 2333
    45 ooooppppp
    46 yoo
    47 '''
    48 
    49 new_1 = {'A':'asss','B':'bssss','C':'asss','D':'bssss'}
    50 new_2 = {'lll':'asss',123:'bssss','A':'asss','B':'bssss','C':'asss','D':'bssss'}
    51 new_3 = {'Appp':'asss','B':'bs'}
    52 arr = [new_1,new_2,new_3]
    53 for a in arr[:3]:
    54     a['A'] = '1234'
    55     a['D'] = 'lllllllll'
    56 print arr
    57 
    58 '''
    59 [{'A': '1234', 'C': 'asss', 'B': 'bssss', 'D': 'lllllllll'}, {'A': '1234', 'C': 'asss', 'B': 'bssss', 'D': 'lllllllll', 'lll': 'asss', 123: 'bssss'}, {'A': '1234', 'B': 'bs', 'D': 'lllllllll', 'Appp': 'asss'}]
    60 
    61 '''
    62 print arr[1].keys()
    63 print arr[1].items()
    64 #['A', 'C', 'B', 'D', 'lll', 123]
    65 #[('A', '1234'), ('C', 'asss'), ('B', 'bssss'), ('D', 'lllllllll'), ('lll', 'asss'), (123, 'bssss')]
    66 for a in arr:
    67     for k,v in a.items():
    68         print k,"	",v
    69 
    70 '''
    71 A       1234
    72 C       asss
    73 B       bssss
    74 D       lllllllll
    75 A       1234
    76 C       asss
    77 B       bssss
    78 D       lllllllll
    79 lll     asss
    80 123     bssss
    81 A       1234
    82 B       bs
    83 D       lllllllll
    84 Appp    asss
    85 '''
    86 new_4={'kkkkk':{'opoppo':123}}
    87 arr.append(new_4)
    88 for value in arr[3].values():
    89     for key2 in value:
    90         print key2
    91 #opoppo
  • 相关阅读:
    树形DP新识
    HDU3652 B-number 数位DP第二题
    HDU3555 Bomb 数位DP第一题
    数位DP新识
    Codeforces Round #371 & HihoCoder1529【玄学】
    hihocoder1618 单词接龙
    后缀数组 逐步探索
    HDU2157 How many ways矩阵再识
    阿里云安全中心:自动化安全闭环实现全方位默认安全防护
    趣谈预留实例券,一文搞懂云上省钱最新玩法
  • 原文地址:https://www.cnblogs.com/yuanjingnan/p/11131189.html
Copyright © 2020-2023  润新知