这个程序如何用Python 语言编写

Write a program that categorizes each mail message by which day of the week the commit was done. To do this look for lines that start with “From”, then look for the third word and keep a running count of each of the days of the week. At the end of the program print out the contents of your dictionary (order does not matter).

img

麻烦给出一个完整的程序

file = input("name: ")
with open(file,"r") as f:
    read = f.readlines()
read = [i.split() for i in read]
reee = []

for i in read:
    if i[0] == "From":
        reee.append(i)

dic = {}

for i in reee:
    if i[2] == "Mon":
        dic[i[2]] = dic.get(i[2],0)+1
    if i[2] == "Tue":
        dic[i[2]] = dic.get(i[2],0)+1
    if i[2] == "Wed":
        dic[i[2]] = dic.get(i[2],0)+1
    if i[2] == "Thu":
        dic[i[2]] = dic.get(i[2],0)+1
    if i[2] == "Fri":
        dic[i[2]] = dic.get(i[2],0)+1
    if i[2] == "Sat":
        dic[i[2]] = dic.get(i[2],0)+1
    if i[2] == "Sun":
        dic[i[2]] = dic.get(i[2],0)+1
print(dic)
dirname=r'C:\Users\Administrator\Desktop'

from collections import Counter

with open(dirname + "/xx.txt", encoding = 'utf-8') as f:
    lines =[i.split()[2] for i in f.readlines() if i.startswith('From')]
    d = dict(Counter(lines))
    print(d)

filename = input("Enter a file name:")
with open(dirname + "/" + filename, 'w', encoding = 'utf-8') as f:
    f.write(str(d))

img

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632