【发布时间】:2020-07-15 03:14:22
【问题描述】:
我有一个文本文件'news.txt',我试图将每一行的第三个单词保存在一个列表中(三个),我只是不断地得到一个向量,其中包含一行中的第三个单词,它没有'似乎没有在以下几行中注册其他单词。
with open('news.txt', 'r') as file:
content = file.read()
words = content.split()
for bwords in words:
three = bwords[2]
【问题讨论】:
-
three = [word[2] for word in words.split()]