# f = open('E:\\城市对应的编号.txt','r+') # li = f.readlines() # print(type(li)) # print(li)
ss = '北京:101010100朝阳:101010300顺义:101010400怀柔:101010500通州:101010600昌平:101010700' import re l = re.findall(r'\d{9}',ss) #这是处理 数字的 s = re.findall(r'[\u4e00-\u9fa5]+',ss) #这是处理文字的
city_dict = {}
with open('E:\\城市对应的编号.txt','r+',encoding='GBK') as f: city_no = f.read() l1 = re.findall(r'[\u4e00-\u9fa5]+:\d{9}',city_no)
#print("li--------------",l1) #['北京:101010100', '朝阳:101010300', '顺义:101010400', '怀柔:101010500', #print("li_type--------------", type(l1)) #list for i in l1: s = i.split(":") city_dict[s[0]] = s[1]