with open(data_path) as f:
content = f.readlines()
content = [x.strip() for x in content]
Run Code Online (Sandbox Code Playgroud)
以下代码将读取每一行并将其插入列表中.但我想要的代码应该读取第一行并跳过第二行然后读取第三行或简单地调整内容以"删除"具有odd索引号的值.
只需在列表理解中将步等于2即可
content = [x.strip() for x in content[::2]]
Run Code Online (Sandbox Code Playgroud)