使用“或”来查找csv文件中一行中是否有任何字符串[重复]

问题描述 投票:-1回答:1
示例文件(.csv):在行[0]中有“ d e f b c c c c a”]

file=open("example_file.csv","r") column="" for row in file: if "a" or "b" or "c" in row[0]: column+=row

[我正在尝试找出一种方法,如果文件中的行中有a,b或c,它将仅打印a,b或c]
python csv boolean boolean-logic opencsv
1个回答
0
投票
您可以使用any function

if (any(x in row[0] for x in ("a", "b", "c"))): column += row

© www.soinside.com 2019 - 2024. All rights reserved.