Process the code corresponding to the city, regular classic example

# f = open('E:\\ number corresponding to the city.txt','r+') 
# li = f.readlines()
# print(type(li))
# print(li)

ss = 'Beijing: 101010100 Chaoyang :101010300Shunyi:101010400Huairou:101010500Tongzhou:101010600Changping:101010700'
import re
l = re.findall(r'\d{9}',ss) #This is
s = re.findall(r'[\ u4e00-\u9fa5]+',ss) #This is the

city_dict for text processing = {}

with open('E:\\the number corresponding to the city.txt','r+',encoding='GBK') as f:
city_no = f.read()
l1 = re.findall(r'[\u4e00-\u9fa5]+:\d{9}',city_no)

#print("li------------- -",l1) #['Beijing:101010100', 'Chaoyang:101010300', 'Shunyi:101010400', 'Huairou:101010500',
#print("li_type-------------- ",type(l1)) #list
for i in l1:
s = i.split(":")
city_dict[s[0]] = s[1]

print(city_dict)
print(city_dict['Xianyang'])
print(city_dict.values())
print(type(city_dict))


# print("type city_dict:",type(city_dict))
# print(city_dict)
all = re .findall(r'[\u4e00-\u9fa5]+:\d{9}',ss) #************************** **************************************************** ***
'''
print("all:",all)
'Beijing: 101010100', 'Chaoyang: 101010300', 'Shunyi: 101010400', 'Huairou: 101010500', 'Tongzhou: 101010600', 'Changping: 101010700'

\u4e00-\u9fa5
unicode encoding, an encoding included in languages ​​all over the world. (Commonly used in the internationalization function)
\u4e00-\u9fa5 may be a condition used to judge whether it is Chinese. There is no introduction to this, just to find which country's language is in which range.

+ can match


'''



''' repeatedly






'''


'''
r escape
. Match any character except newline
? The preceding character can appear at most 0 or 1 times

for i in re.findall(r'.+?:\d{9}', ss):
print(i)


'''



# print("l:",l)
# print("type l:",type(l))
#
# print("s:",s)
# print("type s",type(s))
#
# print("all:",all)
# print("type all:",type(all))
# print('------------- -------------------')
# print(all[0])
# print(re.findall(r'\d{9}',all[0]) )
# print(type(re.findall(r'\d{9}',all[0])))

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326357742&siteId=291194637