telecom dict

http://telecommunication.telecommunication.techdictionary.org/CLIR
首先,需要准备一个包含电话号码的文本文件,假设它的名字是"phone_numbers.txt"。然后,使用Python中的re模块来编写正则表达式,匹配电话号码的开头数字,以区分不同的运营商。最后,使用pandas模块将分类后的结果存储为xlsx文件。 下面是一个示例代码: ```python import re import pandas as pd # 读取电话号码文本文件 with open('phone_numbers.txt', 'r') as f: phone_numbers = f.read().splitlines() # 定义正则表达式,匹配电话号码的开头数字 regex_dict = { 'China Mobile': re.compile('^1(3[4-9]|4[7]|5[012789]|7[8]|8[23478])\d{8}$'), 'China Unicom': re.compile('^1(3[0-2]|4[5]|5[56]|7[6]|8[56])\d{8}$'), 'China Telecom': re.compile('^1(3[3]|4[9]|53|7[7]|8[019])\d{8}$') } # 对电话号码进行分类 result_dict = {} for phone_number in phone_numbers: for operator, regex in regex_dict.items(): if regex.match(phone_number): if operator in result_dict: result_dict[operator].append(phone_number) else: result_dict[operator] = [phone_number] # 将分类结果存储为xlsx文件 writer = pd.ExcelWriter('phone_numbers.xlsx') for operator, phone_numbers in result_dict.items(): df = pd.DataFrame(phone_numbers, columns=[operator]) df.to_excel(writer, sheet_name=operator, index=False) writer.save() ``` 在运行完上述代码后,就会在当前目录下生成一个名为"phone_numbers.xlsx"的文件,其中包含三个工作表,分别对应于中国移动、中国联通和中国电信的电话号码。每个工作表中的数据都是相应运营商的电话号码,没有重复项。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值