可以通过使用Python的字典和文件读取功能来解决这个问题。首先,可以使用open()函数读取文件,然后使用字典来存储每个人发送的邮件数量,并遍历文件中的每个行来更新字典。最后,可以使用max()函数找到字典中发送邮件最多的人。
代码示例:
filename = input("Enter file name: ") fhandle = open(filename)
counts = dict() for line in fhandle: if line.startswith("From "): words = line.strip().split() email = words[1] counts[email] = counts.get(email, 0) + 1
max_count = 0 max_email = "" for email, count in counts.items(): if count > max_count: max_count = count max_email = email
print(max_email, max_count)