Advertisement
Lyubohd

02. Mirror Words

Jul 30th, 2020
1,634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. import re
  2.  
  3. regex = r"(@|#)([A-Za-z]{3,})\1\1([A-Za-z]{3,})\1"
  4.  
  5. data = input()
  6. mirror_words = []
  7.  
  8. match = re.findall(regex, data)
  9.  
  10. for m in match:
  11.     first_word = m[1]
  12.     second_word = m[2]
  13.     if first_word == second_word[::-1]:
  14.         mirror_words.append(first_word + " <=> " + second_word)
  15.  
  16. if len(match) == 0:
  17.     print("No word pairs found!")
  18. else:
  19.     print(f"{len(match)} word pairs found!")
  20.  
  21. if len(mirror_words) == 0:
  22.     print("No mirror words!")
  23. else:
  24.     print("The mirror words are:")
  25.     print(", ".join(mirror_words))
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement