Check a string for any items in an array

前端 未结 1 1501
别那么骄傲
别那么骄傲 2021-01-27 14:22

I have an string (items with comma separated) and I need to check if any of the items in the string (or list after split) are present in a long string.

I know how to do

相关标签:
1条回答
  • 2021-01-27 15:09

    Use any checking if any word is in test :

    if any(word in test for word in people.split(",")):
       # do whatever
    

    Your logic is incorrect as you are checking test is in the split list of words which does not match your first loop.

    0 讨论(0)
提交回复
热议问题