Question: My code writes emails to a text file, but I need them to be listed in the text file like so: a@abc.com b@abc.com c@abc.com In

My code writes emails to a text file, but I need them to be listed in the text file like so:

a@abc.com

b@abc.com

c@abc.com

In other words, I need them in one vertical column, a new line after each email, written to the text file.

How could i do this?

My code is:

import re f = open("wos.txt", "r") ff = (f.read()) #print(ff) f.close() email_pattern = re.compile(r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}') # define an email pattern text = ff a = email_pattern.findall(ff) length_list = [len(element) for row in a for element in row] column_width = max(length_list) for row in a: row = "".join(element.ljust(column_width) for element in row) print(row) b = row #print(email_pattern.findall(ff), items) g = open("output.txt", "w") g.write(" ".join(a)) g.close() #close the file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!