我将字符串段落作为输入,然后使用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)谢谢
发布于 2019-08-02 18:20:00
在代码中,
...
words = line.split()
print(words)https://stackoverflow.com/questions/57320059
复制相似问题