#!/usr/bin/env python
# -*- coding:utf-8 -*-
info={ #字典赋值
'aa':'11','xx':'44',
'bb':'22','yy':'55',
'cc':'33','zz':'66',
}
print('1 ',info)
print('2 ',info['cc']) #取值
info['cc']='99' #改值
print('3 ',info)
del info['cc'] #删除
info.pop('aa') #删除
info.popitem() #随机删
print('4 ',info)
print('5 ',info.get('bb')) #查询
print('6 ', 'yy' in info) #查询yy是否在info中
print('++++++++++++++++++++++++')
abc={
"神仙":{
'玉帝':['天庭'],
'悟空':['齐天大圣','斗战胜佛'],
'老君':['太上老君']
},
'妖怪':{
'牛魔王':['大力牛魔王','妖魔'],
'白骨精':['三次整容'],
'金鹏王':['狮子精']
},
'人类':{
'皇上':['主宰'],
'宰相':['一人之下万人之上'],
'将军':['一将成功万骨枯']
}
}
print(abc)
abc['神仙']['悟空'][1]='美猴王'
print(abc['神仙'])
print('++++++++')
a={1:2,3:4}
b={1:9,5:6}
a.update(b) #有相同的替换,不同的则追加
print(a)
c=dict.fromkeys([7,8,9],'test') #dict是临时值,不重要
print(c)
c=dict.fromkeys([7,8,9],[1,{'qq':'99'},777]) #dict是临时值,不重要,所有值一样
print(c)
c[8][1]['qq']='QQ' #改一个时,全改
print(c)
#字典循环
for i in abc:
print(i)
for i in abc: #少用
print(i,abc[i]) #不高效
print('+++')
for i,j in abc.items(): #高效
print(i,j)
print('++++++++++++')
#三层菜单
abc={
'a': {
"a1": {
"a12": ["a121", "a122"],
"a12": ["a121", "a122"]
},
"a2": {
"a21": ["a211", "a212"],
"a22": {"a221", "a222"},
"a23": {"a231", "a232"},
},
"a3": {},
},
'b': {
"b1": {},
"b2": {},
"b3": {}
},
'c': {
"c1": {},
"c2": {},
"c3": {},
},
}
x=True
while x:
for i in abc:
print(i) #显示第一层所有
a = input("选择进入1>>:")
if a in abc:
while x:
for i2 in abc[a]:
print("\t",i2) #显示第二层所有
b = input("选择进入2>>:")
if b in abc[a]:
while x:
for i3 in abc[a][b]:
print("\t\t", i3) #显示第三层所有
c = input("选择进入3>>:")
if c in abc[a][b]:
for i4 in abc[a][b][c]:
print("\t\t",i4) #显示第四层所有
d = input("最后一层,按b返回>>:")
if d == "b":
pass
elif d == "q":
x = False
if c == "b":
break
elif c == "q":
x = False
if b == "b":
break
elif b == "q":
x = False
if a=='q':
x = False