Project - Churn Emails Inbox with Python

You are currently auditing this course.
5 / 10

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.

Get Hint See Answer

Loading comments...