Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions