Sep-04-2019, 06:08 PM
This gives me the desired output:
What am I not understanding here?
targetfile = input(' Enter a file name: ') #senders = [] --I don't think I need to create a list, do I? sendercount = 0 #this counts number of senders fhand = open(targetfile) for line in fhand: words = line.split() if len(line) < 3: continue #guardian to skip blank or short lines if words[0] == "From" and words[0]!= "From:": #senders.append(words[1]) sendercount = sendercount + 1 print(words[1]) else: continue print('There were',sendercount,'lines in the file with From as the first word.')Not sure I really had it, I changed 8 to:
if words[0] != "From" and words[0] == "From:":I got the exact same output: same e-mail addresses (second word in the format) and same number of lines (sendercount). With the first attempt I aimed to exclude the colon. The second attempt aims to include the colon.
What am I not understanding here?