0

I have used the + and $ to mark the beginning and end of the word but I don't know how to put it into compile without a syntax error. What keeps happening is the match will find the bigger word too, I just want the exact match.

>>> mumu = ["act", "magic", "lose", "dance"]
>>> matcher = ["That is a terrible actor", "This is the first act", "It works like magic", "That's because he is a magician", "Don't be afraid to lose", "Don't be a loser", "Try this dance", "It won't make you a dancer"]
> 
> >>> def intermediate(first, second):
...     dul = len(second)
...     milly = cycle(second)
...     for y in range(dul):
...         t = re.compile(next(milly))
...         for i in first:
...             print(t)
...             if re.search(t, i) != None:
...                 print(i)
...                 dul -= 1
...                 continue
...             else:
...                 print("try again")
...                 dul -= 1
...                 continue
...         continue

And the result is

re.compile('act')
That is a terrible actor
re.compile('act')
This is the first act
Ryan M
  • 18,333
  • 31
  • 67
  • 74

0 Answers0