Hi everyone I am writing this program that takes a string and search it for words. Those words are taken and they get "<" at the beginning and ">" at the end of the word. then it prints the string with the words and the "<, >" characters.
Here is my code:
def test(): import re a = "<" b = ">" c = "Hello this is a test" d = re.findall(r"\bthis\b|\ba\b", c) e = re.split(r"\bthis\b|\ba\b", c) for item in d: y = item f = a+y+b output = f.join(re.split(r"\bthis\b|\ba\b", c)) print output
When I run this code I get this answer:
Hello <a> is <a> test
However the answer I want is this:
Hello <this> is <a> test
Can anyone please tell me how to solve this problem? thanks in advance.