Python 代码优化:提取并去重手机号码
import re
phoneList = []
with open('contact.csv', 'r', encoding='utf-8') as f: records = f.readlines() for record in records: phonePattern = re.compile(r'\d{10}') phone = re.findall(phonePattern, record) if len(phone) > 0: phoneList.extend(phone)
uniqueList = list(set(phoneList)) uniqueList.sort(key=phoneList.index) keywordList = uniqueList
print('Total: ' + str(len(uniqueList)) + ' Records.')
原文地址: https://www.cveoy.top/t/topic/lQvF 著作权归作者所有。请勿转载和采集!