I want to know whether a list content is in a long string. such as:
aa=["column","is","the","word","others", "excludition"] # the list content
bb="from the long text" #the long string
cc=[wd in bb for wd in aa]
but the cc
is [False, False, True, False, False, False]
.
I want to need the True. if one of the items is true.
How to do?
CodePudding user response:
You can use any
:
cc=any([wd in bb for wd in aa])
CodePudding user response:
aa=["column","is","the","word","others", "excludition"] # the list content
bb="from the long text" #the long string
cc=[wd in bb for wd in aa]
if any(word in bb for word in aa):
print('yes')