0

I have written below program. Is there a better way (efficient one) to rewrite the code?

##Read through mailbox data. Find line starting with 'From' and split those into words. Fetch the email #address (second word) and print. Also count the total number of 'From' lines and print at end.

with open("mbox-short.txt", mode='r') as f:
        data = f.readlines()
count=0
for line in data:
    words = line.split()
    if line.startswith ('From:'):  continue
    if line.startswith ('From'):  
      email_sent_by= words[1]
      print(email_sent_by)
      count=count+1
print('There were',count,'lines in the file with From as the first word.')

0 Answers0