Activity 10.11.1.
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 the dictionary
mail_count (order does not matter). For example, mail_count['Mon'] should be 2.
Solution.
βFromβ
# mail list was given
mail = ['From [email protected] Sat Jan 7', 'From [email protected] Thurs Jan 5', 'From [email protected] Tues Jan 3', 'From [email protected] Sat Jan 7', 'From [email protected] Wed Jan 4', 'From [email protected] Mon Jan 2', 'From [email protected] Mon Jan 2', 'From [email protected] Fri Jan 6']
# Create dictionary for the emails
mail_count = {}
# Iterate through each email in the list
for email in mail:
# Separate pieces of each email setting key to the day (third element)
key = email.split()[2]
# Add key to dictionary if not included
if key not in mail_count.keys():
mail_count[key] = 0
# Update key
mail_count[key] += 1
# Print final count
print(mail_count)

