Skip to content
  • About
  • CoursesExpand
    • Problem Solving using C Language
    • Mastering Database Management
    • Linux System Administration
    • Linux and Shell Programming
  • Publications
  • Professional Certificates
  • BooksExpand
    • Books Authored
  • Patents
Download CV
Python

Churn Email: Day of the Week

Python Project – Churn Emails – Find Which Day of the Week the Email was sent

Write a function find_email_sent_days which reads the file /datasets/project/mbox-short.txt and categorizes each mail message by which day of the week the email was sent.

To do this do the following:

  • Open the file and read it line by line
  • Look for lines that start with “From“
  • For those lines which start from “From“, then look for the third word and keep a running count of each of the days of the week. How do you find the day of the week, is an exercise for you.

Note: You have to store the results in a dictionary. Only store those day of the week that exists. For Example, if there is no line for Mon then it should not be in the dictionary elements.

  • At the end of the program return the contents of your dictionary (order does not matter)

Sample Lines from the file:

From stephen.marquard@uct.ac.za Sat Jan  5 10:14:16 2008
From stephen.marquard@uct.ac.za Sat Jan  5 15:14:16 2008
From stephen.marquard@uct.ac.za Sun Jan  6 09:14:16 2008

Output:

{'Sat': 2, 'Sun': 1}

PS – If your logic is correct then your function should return this dictionary {'Sat': 1, 'Fri': 20, 'Thu': 6}.

Code:

def find_email_sent_days():
    with open("/cxldata/datasets/project/mbox-short.txt") as f:
        days = [i.split(' ')[2] for i in f if i.startswith('From ')]
        print (days)
        dic = {}
        for day in days:
            dic[day] = days.count(day)        
        return dic

Post navigation

Previous Previous
Compute the Compound Interest.py
NextContinue
Churn Emails – Count Number of Messages
Latest

Advance AI PPT

Read More Advance AI PPTContinue

Latest

Prompts for Image Descriptions

Describe the scene using three vivid sensory details — one for sight, one for sound, and one for touch. Summarize the mood of the image…

Read More Prompts for Image DescriptionsContinue

Latest

Dimensionality Reduction

Dimensionality reduction is the process of reducing the number of features (variables) in a dataset while preserving important information. It helps in: ✅ Reducing computational…

Read More Dimensionality ReductionContinue

Artificial Intelligence

Tanh Function in Neural Network

The tanh function, short for hyperbolic tangent function, is another commonly used activation function in neural networks. It maps any real-valued number into a value…

Read More Tanh Function in Neural NetworkContinue

Latest

Why Initialize Weights in Neural Network

Initializing weights and biases is a crucial step in building a neural network. Proper initialization helps ensure that the network converges to a good solution…

Read More Why Initialize Weights in Neural NetworkContinue

Nishant Munjal

Coding Humanity’s Future </>

Facebook Twitter Linkedin YouTube Github Email

Tools

  • SIP Calculator
  • Write with AI
  • SamplePHP
  • Image Converter

Resources

  • Blog
  • Contact
  • Refund and Returns

Legal

  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

© 2025 - All Rights Reserved

  • About
  • Courses
    • Problem Solving using C Language
    • Mastering Database Management
    • Linux System Administration
    • Linux and Shell Programming
  • Publications
  • Professional Certificates
  • Books
    • Books Authored
  • Patents
Download CV
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok