Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left
Apply NowLogin using Social Account
     Continue with GoogleLogin using your credentials
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()
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:
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 forMon
then it should not be in theMap
elements.
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)
.
Taking you to the next exercise in seconds...
Want to create exercises like this yourself? Click here.
No hints are availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here
Loading comments...