python - 将文件中每一行的第三个单词分配给 Python 中的列表
问题描述
我有一个文本文件'news.txt'
,我正在尝试将每一行的第三个单词保存在一个列表中(三个),我只是一遍又一遍地得到一个带有第三个单词的向量,它似乎没有注册以下几行中的其他词。
with open('news.txt', 'r') as file:
content = file.read()
words = content.split()
for bwords in words:
three = bwords[2]
解决方案
with open('news.txt', 'r') as file:
content = file.read()
words = content.split()
for bwords in words[::3]:
three = bwords
推荐阅读
- input - ffpmeg 强制覆盖(严重)检测到的输入帧率
- css - CSS 背景图片 - 如何设置图片停留在原位
- laravel - 为什么按计划运行的日志:在 Laravel Vapor 上运行而不保存在 Cloudwatch 中?
- reactjs - 如何让组件在 React 中只加载一次?
- blockchain - 我如何在区块链网络上部署我的合约?
- rust - 在 Rust 中将方法作为参数提供(Vec sort() 方法)
- gcc - 使用 map 并使用 clang 编译时未定义的引用 eeror [abi:cxx11]
- php - 获取 PHP 函数 (Symfony 4.2)
- r - Wu Hausman 检验检验内生性
- function - LLVM 中多个程序集文件的内联函数