class Infomation:
def __init__(self, id, code):
self.id = id
self.code = code
location = dict() # 创建字典
e = [
{"id":"11","name":"北京","code":"11"},
{"id":"18","name":"河北","code":"18"},
{"id":"38","name":"福建","code":"38"},
{"id":"75","name":"江西","code":"75"},
{"id":"17","name":"山东","code":"17"},
{"id":"76","name":"河南","code":"76"},
{"id":"71","name":"湖北","code":"71"},
{"id":"74","name":"湖南","code":"74"},
{"id":"51","name":"广东","code":"51"},
{"id":"59","name":"广西","code":"59"},
{"id":"13","name":"天津","code":"13"},
{"id":"50","name":"海南","code":"50"},
{"id":"83","name":"重庆","code":"83"},
{"id":"81","name":"四川","code":"81"},
{"id":"19","name":"山西","code":"19"},
{"id":"85","name":"贵州","code":"85"},
{"id":"86","name":"云南","code":"86"},
{"id":"79","name":"西藏","code":"79"},
{"id":"84","name":"陕西","code":"84"},
{"id":"87","name":"甘肃","code":"87"},
{"id":"70","name":"青海","code":"70"},
{"id":"88","name":"宁夏","code":"88"},
{"id":"89","name":"新疆","code":"89"},
{"id":"10","name":"内蒙古","code":"10"},
{"id":"91","name":"辽宁","code":"91"},
{"id":"90","name":"吉林","code":"90"},
{"id":"97","name":"黑龙江","code":"97"},
{"id":"31","name":"上海","code":"31"},
{"id":"34","name":"江苏","code":"34"},
{"id":"36","name":"浙江","code":"36"},
{"id":"30","name":"安徽","code":"30"}]
for i in e:
location[i["name"]] = Infomation(i["id"], i["code"]) # 将资料输入字典
# 范例
x = "山东"
print(x, location[x].id, location[x].code)
y = "四川"
print(y, location[y].id, location[y].code)
z = "上海"
print(z, location[z].id, location[z].code)