【发布时间】:2016-08-21 21:48:37
【问题描述】:
如何使这段代码工作?
我想检查一些子字符串是否在列表中,而另一些不在。
if 'A_' and 'V' and '3' and not 'ES' and not 'SF' in my_list[0:3]:
print("It's True")
【问题讨论】:
标签: python string list python-3.x contains
如何使这段代码工作?
我想检查一些子字符串是否在列表中,而另一些不在。
if 'A_' and 'V' and '3' and not 'ES' and not 'SF' in my_list[0:3]:
print("It's True")
【问题讨论】:
标签: python string list python-3.x contains
您可以使用all() 函数:
if all(x in L for x in wanted) and all(x not in L for x in not_wanted):
# do stuff
【讨论】:
L = my_list[:3]; wanted = ["A_", "V", "3"]; not_wanted = ["ES", "SF"]