Jul-15-2023, 06:21 PM
I've somehow managed to duplicate my results for a short line of code used to extract the emails from a text document. I'm trying to figure out why that's happening and I'm having a bit of trouble coming up with a solution. I figured maybe it had to do with how I wrote the "For" loop. The correct output should be exactly half of what is actually showing. (the "line = line.split()" is for when I print out the emails which is also printing double the emails as well. I didn't include it in this post for privacy reasons.)
fname = input("Enter file name: ") fh = open(fname) count = 0 for line in fh: line = line.strip() if not line.startswith("From"): continue line = line.split() count = count + 1 print("There were", count, "lines in the file with From as the first word")
Output:There were 54 lines in the file with From as the first word