0
word = 'eat'
sent = "we don't beat you we beat the competition"

if word in sent:
    print("Present")

There is no 'eat' in the sentence but still, it is showing that eat is available. I know that eat is within beat but I want to find whether 'eat' alone is available or not instead of present in some other words. How to do it. Thank You.

Khaja
  • 15
  • 1
  • 1
    Does this answer your question? [Check if a word is in a string in Python](https://stackoverflow.com/questions/5319922/check-if-a-word-is-in-a-string-in-python) (check the second answer) – Bill the Lizard Jul 18 '22 at 19:40
  • @BilltheLizard I have seen that question but it doesn't resolve what I have asked. for example word sea is also available in seating and it says available but originally it's not as sea should be alone like sea = sea not sea = seating – Khaja Jul 18 '22 at 19:55
  • @Khaja while not very efficient, you could just split `sent` on spaces after removing all non alpha characters, then check if 'eat' is in the list. i.e. `sent = ''.join(char for char in sent if char.isalpha())`, `sent = sent.split(' ')` and `if word in sent: print("present")` – LPR Jul 18 '22 at 20:05

0 Answers0