def search_specificword(key, stng): key = key.lower() stng = stng.lower() flag_present = False if stng.startswith(key+" "): flag_present = True symb = [',','.'] for i in symb: if stng.find(" "+key+i) != -1: flag_present = True if key == stng: flag_present = True if stng.endswith(" "+key): flag_present = True if stng.find(" "+key+" ") != -1: flag_present = True print(flag_present) return flag_present
Output:search_specificword("Affordable housing", "to the core of affordable outHousing in europe")False
search_specificword("Affordable housing", "to the core of affordable Housing, in europe")True