Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left

  Apply Now

Scala Project - Churn Email Inbox with Scala

5 / 7

Scala Project - Churn Emails - Find Which Day of the Week the Email was sent

In this step we will find the number of emails that were sent in each day of the week using a Map.

In Scala, a Map is a collection of key, value pairs. If you are familiar with Python, then you would find similarities between a Dictionary in Python and a Scala Map. The keys have to be unique in a Map, the values may or may not be unique.

There are two kinds of Maps, the immutable and the mutable. By default, Scala uses the immutable Map. If you want to use the mutable Map, you'll have to import scala.collection.mutable.Map class explicitly.

Here's how you can define a Map in Scala:

var sampleMap:Map[Char,Int] = Map()
INSTRUCTIONS

Write a function find_email_sent_days which reads the file /cxldata/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 Map. 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 Map elements.

  • At the end of the program return the contents of your Map (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}

Note: If your logic is correct then your function should return the following Map(Thu -> 6, Fri -> 20, Sat -> 1).

See Answer

No hints are availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...