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

2 / 7

Scala Project - Churn Emails - Count the Number of Lines

Scala uses scala.io.Source class to read the files from the operating system. Here is one example code on how you can read each line from a file named new.txt:

import scala.io.Source;
for (line <-Source.fromFile("new.txt").getLines) {
    println(line)
}

A complete file path can also be specified instead of a standalone file name.

INSTRUCTIONS
  • Define a function number_of_lines
  • Open the file mbox-short.txt which is located at /cxldata/datasets/project/mbox-short.txt and read it to get each line using getLines function
  • Write the logic to count the total number of lines
  • Return the count of the number of lines
  • Call the function in the next cell

Note: If your logic is correct then your function should return 1910.

See Answer

No hints are availble for this assesment


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

Loading comments...