whartonone
whartonone

Reputation: 33

Want to create a list from column of strings

I take a string paragraph as input then use rstrip() to strip it into rows, then split() to strip each row into words.

So I'm left with a column of strings:

Barry Sally Andrew Jonathan ...

How can I create a list from this output?

(I want this as output) => ['Barry', 'Sally', 'Andrew', 'Jonathan', ...]

file_name = input("Enter file name: ")
file_holder = open(file_name)

for line in file_holder:

 # strip into rows
    line = line.rstrip()
    if not line.startswith("From "): continue
    # strip into words
    words = line.split()
    email_list = words[1]
    print(email_list)

Thanks

Upvotes: 0

Views: 58

Answers (1)

ggmu_reddevils
ggmu_reddevils

Reputation: 101

In your code,

...
words = line.split()
print(words)

Upvotes: 1

Related Questions