GeorgiLukanov87

Mirror Words judge 100/100

Jul 13th, 2022 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. # 02. Mirror Words , 03. Programming Fundamentals Final Exam Retake 100/100
  2. # https://judge.softuni.org/Contests/Practice/Index/2307#1
  3.  
  4. import re
  5.  
  6. string_data = input()
  7.  
  8. pattern = r'(\@|\#)([A-Za-z]{3,})\1(\@|\#)([A-Za-z]{3,})\3'
  9.  
  10. hidden_pairs = re.finditer(pattern, string_data)
  11. pairs_found = 0
  12. valid_pairs = []
  13.  
  14. for pair in hidden_pairs:
  15.     pairs_found += 1
  16.     word1 = pair.group(2)
  17.     word2 = pair.group(4)
  18.     if word1 == word2[::-1]:
  19.         valid_pairs.append(f'{word1} <=> {word2}')
  20.  
  21. if pairs_found > 0:
  22.     print(f"{pairs_found} word pairs found!")
  23. else:
  24.     print('No word pairs found!')
  25.  
  26. if valid_pairs:
  27.     print(f'The mirror words are:')
  28.     print(f'{", ".join(valid_pairs)}')
  29. else:
  30.     print('No mirror words!')
Add Comment
Please, Sign In to add comment