python三级字典_python_三级字典
data = {
"北京":{
"昌平":{
"沙河":["oldboy","test"],
"天通苑":["鏈家地產","我愛我家"]
},
"朝陽":{
"望京":["奔馳","陌陌"],
"國貿":["CICC","HP"],
"東直門":["Advent","飛信"]
},
"海淀":{}
},
"山東":{
"德州":{"a":[1,2]},
"青島":{"b":[3,4]},
"濟南":{"c":[5,6]}
},
"廣東":{
"東莞":{"d":[7,8]},
"常熟":{"e":[9,2]},
"佛山":{"f":[10,2]}
}
}
exit_flag = False
while not exit_flag:
for i in data: #第一層
print(i)
choice = input("選擇進入>>>1:")
if choice in data:
while not exit_flag:
for i2 in data[choice]: #第二層
print("\t",i2)
choice2 = input("選擇進入>>>2:")
if choice2 in data[choice]:
while not exit_flag:
for i3 in data[choice][choice2]: #第三層
print("\t",i3)
choice3 = input("選擇進入>>>3:")
if choice3 in data[choice][choice2]:
for i4 in data[choice][choice2][choice3]: #第四層
print("\t",i4)
choice4 = input("最后一層,按b返回>>:")
if choice4 == ‘b‘:
pass #pass什么也不做,為了讓代碼不出錯,占位符
elif choice4 == ‘q‘:
exit_flag =True
if choice3 == ‘b‘:
break
elif choice3 == ‘q‘:
exit_flag = True
if choice2 == ‘b‘: break elif choice2 == ‘q‘: exit_flag = True
總結
以上是生活随笔為你收集整理的python三级字典_python_三级字典的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pythonwebsocket接口自动化
- 下一篇: 揭秘m9a内存功耗:比传统DDR4低20