0
list = ['hi', 'hello', 'pee', ('poo' , 'pap') , 'noog']

post_lower = ' i am a big idiot'
if any(word in post_lower for word in list):
    print('true')
else:
    print('false')

what im trying to do is if there is hi or hello it will return true, however i want it to only return true if BOTH poo and pap is in the string. I am getting TypeError: 'in ' requires string as left operand, not tuple

the reason im making this because im making a bot that recognizes certain keywords in posts, like for example python course and beginner. Now python on it self does not mean anything however if both python course and beginner is in a string it means that the post is asking for best courses for beginners. However it can be worded differently and have different grammar

thanks for your help

1
  • 1
    word in post_lower is actually each_character in post_lower because iterating over a string means iterating over individual characters. Commented Aug 18, 2022 at 18:20

1 Answer 1

1
list = ['hi', 'hello', 'pee', ('poo' , 'pap') , 'noog']

post_lower = ' i am a big idiot'
for item in list:
    if type(item) == str and item in post_lower:
        print('true')
    elif type(item) == tuple and all(word in post_lower for word in item):
        print('true')
    else:
        print('false')
   
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.