Detect the Word | Python Language Forum
H
Heena Goyal Posted on 04/08/2023
Write a program to find out whether a given post is talking about "Immune" or not?
Please note that the program should be able to detect the word irrespective of letters being in lower case or upper case. 



post='''Our immune system is an intricate network of cells, tissues, 
and organs that work together to protect our bodies from harmful 
invaders, such as bacteria, viruses, and other pathogens. 
It serves as our body's defense system, identifying and eliminating 
threats to maintain our health. Let's explore how our immune system fights disease in simple terms.'''



I am unable to think how to solve this one.

It's practically not possible to mention all the possible probabilities of the word "immune" having lower case and upper case letters in the code.

Please suggest how to solve this one.

Y
Yogesh Chawla Replied on 04/08/2023

You can write like this:

post='''Our IMMUNE system is an intricate network of cells, tissues, 
and organs that work together to protect our bodies from harmful 
invaders, such as bacteria, viruses, and other pathogens. 
It serves as our body's defense system, identifying and eliminating 
threats to maintain our health. Let's explore how our IMMUNE system fights disease in simple terms.'''

import re #importing regular expression library

wordToSearch = "immune"
listOfWordsInParagragh = re.split("[\W]+", post)
print(type(listOfWordsInParagragh))
print(listOfWordsInParagragh)
if wordToSearch.casefold() in (word.casefold() for word in listOfWordsInParagragh):
    print(f'{wordToSearch} is present in the paragraph')
else:
    print(f'{wordToSearch} is not present in the paragraph')


M
Replied on 05/08/2023

Please help me with the syntax for this module step by step first as I am not able to understand any part of this.