0

I want to check one list contains some keywords.

My writing is below:

if ('keyword1' or 'keyword2' or 'keyword3') in [list]:

above works, but seems not good writing.

Any other method to improve it?

AChampion
  • 29,683
  • 4
  • 59
  • 75
Haibo LIN
  • 1
  • 2
  • That is not doing what you think it is doing. Consider it this way: ``('keyword1' or 'keyword2' or 'keyword3')`` is a single expression, which necessarily evaluates to a single value (which happens to be ``'keyword1'`` in this case). That one value is the only thing that ``in`` will be looking for within your list. – jasonharper Mar 31 '17 at 01:27

1 Answers1

0

you can use python built-in any method, https://docs.python.org/2/library/functions.html#any

search_terms = ['a', 'keyword1']
list = ['blabla', 'keyword1', 'keyword4']
if any(word in list for word in search_terms):
 // TRUE
Abdallah Alsamman
  • 1,623
  • 14
  • 22