根据中签尾号,分析深圳小汽车车牌摇号数据。
d={}
def analyze_line(line):
if not re.match(r'[0-9]+\s+[0-9]+\s+\S', line): # +表示一个或多个 \s任意空字符 \S非空字符
return #过滤无效行
print(line, end='')
m = re.search(r' [0-9]+', line) #匹配中间的数据,line[m.start[]:m.end()]=' 6687102476010'
if m is None:
return
tail=line[m.end()-1] #提取中签尾号
if tail not in d:
d[tail] = 1
else:
d[tail] += 1
def analyze_main():
my_file = '2022年01月个人指标配置.txt'
try:
fo = open(my_file, "r", encoding='utf-8')
except Exception as err:
print(err)
return
while True:
line = fo.readline()
if not line:
break
analyze_line(line)
fo.close()
print(d)
#content = fo.read()
#print(content)
#analyze_tail_number(content)
if __name__ == '__main__':
print('Analyze car lottery.')
analyze_main()
2022年01月个人指标配置.txt 文件的部分内容如下:
序号 申请编码 姓名
1 7702103732919 严水连
2 6089103473100 吴碧云
3 0813101359715 蒋科成
4 8797104650113 王江燕
5 2199100945302 陈久平
6 5127104663215 胡志文
7 6148103738872 陈加丽
8 5830100200031 张航
9 1117102928251 方盼盼
10 7678101016178 汪斌
11 9864104226600 李铃
12 9190104254810 关健
13 5507102643444 廖辉远
14 6859103445581 李昶良
15 6705104832513 谢协宏
16 9730100044604 李治国
17 0187104224398 邓志平
18 2129102510296 邓建林
19 9911103971047 李彦旸
20 8398100701381 王晓辉
21 4382104022194 林颖
-2-
22 3186104464116 唐李宗
23 3798100880929 郭华容
运行结果:
{‘9’: 27, ‘0’: 34, ‘5’: 28, ‘3’: 30, ‘2’: 39, ‘1’: 40, ‘8’: 24, ‘4’: 31, ‘6’: 39, ‘7’: 33}