Login using Social Account
     Continue with GoogleLogin using your credentials
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)
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.
Taking you to the next exercise in seconds...
Want to create exercises like this yourself? Click here.
Loading comments...