Only Few Seats Left for Advanced Certification Courses on Data Science, ML & AI by E&ICT Academy IIT Roorkee
Apply NowWe 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)
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.
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...