我对python比较陌生,想做类似的事情:
if value x == any value in list y:
write x
这将通过函数运行,因此只有符合某个标准的解决方案才会在生成时写入csv
答案 0 :(得分:7)
>>> x = 8
>>> if x in (1, 2, 3, 5, 8, 13, 21, 34, 55):
print('x is an early Fibonacci number')
x is an early Fibonacci number
答案 1 :(得分:4)
您可以使用in语法:
if x in ["a", "b", "c"]
... do stuff
如果您关心x的出现次数,您可以使用count:
if y.count(x) == 1
... do stuff
答案 2 :(得分:1)
这对你有用吗?
x = somevalue
y = somelist
if x in y:
print x #not sure if this is what you mean by 'write'