viligen

mirror_words

Nov 28th, 2021
626
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2.  
  3. text = input()
  4. pattern = r"(@|#)([A-Za-z]{3,})\1\1([A-Za-z]{3,})\1"
  5.  
  6. matches = re.finditer(pattern, text)
  7. counter = 0
  8. palindromes = []
  9. for match in matches:
  10.     first_word = match.group(2)
  11.     second_word = match.group(3)
  12.     counter += 1
  13.     if first_word == second_word[::-1]:
  14.         palindromes.append(f"{first_word} <=> {second_word}")
  15.  
  16. if counter == 0:
  17.     print("No word pairs found!")
  18.     print("No mirror words!")
  19. else:
  20.     print(f"{counter} word pairs found!")
  21.     if not palindromes:
  22.         print("No mirror words!")
  23.     else:
  24.         print(f"""The mirror words are:
  25. {", ".join(palindromes)}""")
  26.  
RAW Paste Data