如果字符串包含列表项

If string contains an list item

我正在寻找一种方法来检查字符串中是否包含列表项

test = ['he', 'she', 'them']
string = 'hello'
if any(test in s for s in string):
    print 'yes'

我试试这个,因为 'he' 在 'hello' 它应该打印是,但我得到

TypeError: 'in <string>' requires string as left operand, not list

有什么帮助吗?

不是迭代字符串对象,而是迭代列表对象test

并检查测试项是否在string:

test = ['he', 'she', 'them']
string = 'hello'
if any(test_item  in string for test_item in test):
    print 'yes'