我将一个字符串段落作为输入,然后使用rstrip()
将其剥离为行,然后使用split()将每一行剥离为单词。
所以我剩下一串字符串:
巴里 莎莉 安德鲁 乔纳森 ...
如何从此输出创建列表?
(我希望将此作为输出)=> ['Barry', 'Sally', 'Andrew', 'Jonathan', ...]
file_name = input("Enter file name: ")
file_holder = open(file_name)
对于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)
谢谢
答案 0 :(得分:1)
在您的代码中,
...
words = line.split()
print(words)