直接上代码。
province = {"山东":{"济南":["槐荫区","历下区"],"青岛":["黄岛区","城阳区"],"济宁":"兖州区"},"辽宁":"沈阳","吉林":"长春"}
print(type(province))
char = input("你想查询"
"\n1、市:"
"\/2、县/区:")
if char == '1':
city = input("请出入要查询的城市名:")
for key, val in province.items():
if city in province[key]:
print("该城市属于:",key)
else:
print("数据中暂无该城市。")
break
elif char == '2':
county = input("请出入要查询的县区:")
for key, val in province.items():
#print(province[key])
if isinstance(province[key],dict): #找出值为字典的 键值对
#print(province[key])
for key2 , val2 in province[key].items():#遍历值为字典的部分
# print(province[key].values())
if county in province[key][key2]:
print("该区属于:",key,"省",key2,"市")
else:
print("数据中暂无该区县。")
break
else:
print("输入错误")