Only Few Seats Left for Advanced Certification Courses on Data Science, ML & AI by E&ICT Academy IIT Roorkee

  Apply Now

Python Project - Churn Emails - Count the Number of Lines

If we know the file is relatively small compared to the size of our main memory, we can read the whole file into one string using the read method on the file handle.

Example -

fhand = open('/cxldata/datasets/project/mbox-short.txt')
inp =
  • Define a function number_of_lines
  • Open the file mbox-short.txt which is located at /cxldata/datasets/project/mbox-short.txt
  • Read the file into one string by using read method on file handle
  • Write logic to count the number of lines
  • Return the count of the number of lines

PS - If your logic is correct then your function should return 1910. You can use "Hint" and "See Answer" if you are stuck.

No hints are availble for this assesment

Answer is not availble for this assesment

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

Loading comments...