m0_71814277 2022-06-16 05:57 采纳率: 100%
浏览 104
已结题

这个程序如何用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

麻烦给出一个完整的程序

  • 写回答

3条回答 默认 最新

  • A Python 萌新花花 2022-06-16 08:17
    关注
    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)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 6月24日
  • 已采纳回答 6月16日
  • 赞助了问题酬金10元 6月16日
  • 创建了问题 6月16日