-1

The task is to check for the presence of a word from an array in a string.

str = 'Dear friends, the new model of organizational activity contributes to the preparation and implementation of the personnel training system.'

stop_words = [ 'training', 'moonshine']


if all(stop_words in str):
    print('Find stop word')
else:
    print('All goods, no stop words')

Here python says that he can't compare it. Tell me plese what are the solutions?

Max Watson
  • 101
  • 3

1 Answers1

2

You have the following error

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

As you wan't search a list into a str, that has no sense, you can only search for a string into another string, but you have to do it for each string of your list


Regarding your string no stop words, I guess you want the following, you want any (not each) word from stop_words to be in value

value = 'Dear friends, the new model of organizational activity contributes to the preparation and implementation of the personnel training system.'
stop_words = [ 'training', 'moonshine']

if any(word in value for word in stop_words):
    print('Find a stop word')
else:
    print('All goods, no stop words')
azro
  • 53,056
  • 7
  • 34
  • 70