You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line:
3
+
4
+
From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008
5
+
6
+
You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person who sent the message). Then print out a count at the end.
7
+
Hint: make sure not to include the lines that start with 'From:'.
8
+
9
+
You can download the sample data at mbox-short.txt
10
+
"""
11
+
12
+
fname = input("Enter file name: ")
13
+
if len(fname) < 1 : fname = "mbox-short.txt"
14
+
15
+
fh = open(fname)
16
+
count = 0
17
+
for line in fh:
18
+
if line.startswith("From "):
19
+
words = line.split()
20
+
print(words[1])
21
+
count=count+1
22
+
print("There were", count, "lines in the file with From as the first word")
0 commit comments