res = {} for line in lines: __res.setdefault(re.search('(?<=@).*?(?=:)', line)[0], line) 取 res.values()就得了
biglazycat
2020-10-24 00:33:00 +08:00
import os import re
domain_dict = {} with open('mail.txt', encoding='utf-8') as f: for line in f: domain = re.split('@|:', line)[1] domain_dict.setdefault(domain,[]).append(line) for v in domain_dict.values(): print(v[0])