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

  Apply Now

Python Project - Churn Emails

3 / 7

Python Project - Churn Emails - Count the Number of Subject Lines

We use the string method startswith to select only those lines with the desired prefix.

The below code prints the lines starting with From:

fhand = open('/cxldata/datasets/project/mbox-short.txt')
count = 0
for line in fhand:
    line = line.rstrip() # Remove new line characters from right
    if line.startswith('From:'):
        print(line)
INSTRUCTIONS

Write a function count_number_of_lines which returns the count of the number of lines starting with Subject: in the file /cxldata/datasets/project/mbox-short.txt

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



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

Loading comments...