Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Must be done in Python please. STION In your Python project, create a folder named files. Download input.txt and store it in the files folder.
Must be done in Python please.
STION In your Python project, create a folder named files. Download input.txt and store it in the files folder. Write a program that will go through the lines in input.txt: a. If a line begins with From: i. Extract the email address (please note that the colon is part of the word because there are lines that begin with From without a colon at the end). ii. Keep track of how many times an email is sent from a particular address with the help of a dictionary. iii. Send your dictionary results to an output file called output.csv. This output.csv file shouldn't be stored in the files folder. iv. The last row of data in the csv file should contain the total number of emails. v. The contents of your output.csv file should be identical to sample1.csv. You must use the csv module and its methods to send data to output.csv. b. If a line begins with X-DSPAM-Confidence: i. Send it to an output file named output.txt. This output.txt file should be stored in the files folder. ii. Extract and add the floating-point number on the lines to a running total. iii. When done processing input.txt, display the total and average values of the dspam confidence to 2 decimal places at the very end of output.txt. iv. The contents of your output.txt file should be identical to sample2.txt. Please note: - Write your program as a script (i.e., include the if _ name _ == '_ main '': block). - Use the input and output file names provided in the instructions. - Output files should be opened in write mode not append mode. - Don't forget to close any files you open. - You must use regular expressions to extract the lines that begin with From: and X-DSPAM-Confidence: camnle1 X-DSPAM-Confidence: 0.8475 X-DSPAM-Confidence: 0.6178 X-DSPAM-Confidence: 0.6961 X-DSPAM-Confidence: 0.7565 X-DSPAM-Confidence: 0.7626 X-DSPAM-Confidence: 0.7556 X-DSPAM-Confidence: 0.7002 X-DSPAM-Confidence: 0.7615 X-DSPAM-Confidence: 0.7601 X-DSPAM-Confidence: 0.7605 X-DSPAM-Confidence: 0.6959 X-DSPAM-Confidence: 0.7606 X-DSPAM-Confidence: 0.7559 X-DSPAM-Confidence: 0.7605 X-DSPAM-Confidence: 0.6932 X-DSPAM-Confidence: 0.7558 X-DSPAM-Confidence: 0.6526 X-DSPAM-Confidence: 0.6948 X-DSPAM-Confidence: 0.6528 X-DSPAM-Confidence: 0.7002 X-DSPAM-Confidence: 0.7554 X-DSPAM-Confidence: 0.6956 X-DSPAM-Confidence: 0.6959 X-DSPAM-Confidence: 0.7556 X-DSPAM-Confidence: 0.9846 X-DSPAM-Confidence: 0.8509 X-DSPAM-Confidence: 0.9907 Total dspagm confidence =20.27 Average dspam confidence =0.75Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started