[英]How can I search through a list in python for something that might not exist?
例如:
if l.index(a)== -1:
l += [a]
如果我运行这样的东西,我将得到一个值错误。我假设这不是一个新问题。
为什么不使用:
if a not in some_list:
some_list.append(a)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.