Question: Write a function that given a list of emails, writes the emails to a file called emails.csv Add a header of your choosing to your

Write a function that given a list of emails, writes the emails to a file called "emails.csv"

Add a header of your choosing to your file as the first line.

Your file, emails.csv, will look like this:

list_of_emails

bellamys@mail.med.upenn.edu

warren@upenn.edu

bryanma@upenn.edu

#!/bin/python3

import sys import os

# Complete the function below.

def write_to_csv(list_of_emails):

#write code that should be here

emails = list(map(str.strip, sys.stdin.readlines())) write_to_csv(emails) assert os.path.exists('emails.csv'), 'did you write to "emails.csv"?' with open('emails.csv', 'r') as f: header = f.readline() emails2 = [] for line in f.readlines(): emails2.append(line.strip()) os.remove('emails.csv') assert all(i == j for i, j in zip(emails, emails2)), 'this list of emails is different' assert len(emails) == len(emails2), 'this list of emails is different' print(1)

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!