Advertisement
Osiris1002

Mirror Words

Mar 28th, 2024
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. import re
  2. some_string = input()
  3. mirror_words = []
  4. pattern = r"(?i)(#|@)([a-z]{3,})\1{2}([a-z]{3,})\1"
  5. matches = re.findall(pattern, some_string)
  6.  
  7. if len(matches) == 0:
  8.     print("No word pairs found!")
  9. else:
  10.     print(f"{len(matches)} word pairs found!")
  11.     for match in matches:
  12.         first_word = match[1]
  13.         second_word = match[2]
  14.         if first_word == second_word[::-1]:
  15.             mirror_words.append(f"{first_word} <=> {second_word}")
  16. if len(mirror_words) == 0:
  17.     print("No mirror words!")
  18. else:
  19.     print("The mirror words are:")
  20.     print(*mirror_words, sep=", ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement