关于提取多级字典的值

city_school = {'广州':{'中山大学':['综合性大学','校园优美','MBA去全国一流'],
'广东工业大学':['工业大学']},
'北京':{'清华大学':['中国计算机专业第一名'],
'北京大学':['有丰富的文化底蕴']}
}

def get_key(input_key, my_dict):
for index, key in enumerate(my_dict):
val = my_dict.get(key)
if input_key == key:
'''print(val.keys())'''
input2 = input("请输入你要查找的学校:")
for index, key in enumerate(val):
val1 = val.get(key)
if input2 == key:
'''print(val1)'''
elif index == 1:
print("这所学校没有纳入统计!")
elif index == 1:
print("你输入的城市没有纳入统计!")

if __name__ == '__main__':
input_key = input("请输入你要查找的城市: ");
result = get_key(input_key, city_school)

猜你喜欢

转载自www.cnblogs.com/testa/p/11729824.html