0

trying to find two consecutive words (can have a space or non letter char between them). want to get a list of all words of that sort.

this is my line, text is

text1 = "hi hi, something some bye bye"
cons_lst = re.findall(r'\b(\w+)(\s|\W+)\1+\b',text1)
print(cons_lst) 

what it prints :

[('hi', ' '), ('bye', ' ')]

what i want it to print:

['hi','bye']

thank you!

Wiktor Stribiżew
  • 484,719
  • 26
  • 302
  • 397

0 Answers0