Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 02. Mirror Words , 03. Programming Fundamentals Final Exam Retake 100/100
- # https://judge.softuni.org/Contests/Practice/Index/2307#1
- import re
- string_data = input()
- pattern = r'(\@|\#)([A-Za-z]{3,})\1(\@|\#)([A-Za-z]{3,})\3'
- hidden_pairs = re.finditer(pattern, string_data)
- pairs_found = 0
- valid_pairs = []
- for pair in hidden_pairs:
- pairs_found += 1
- word1 = pair.group(2)
- word2 = pair.group(4)
- if word1 == word2[::-1]:
- valid_pairs.append(f'{word1} <=> {word2}')
- if pairs_found > 0:
- print(f"{pairs_found} word pairs found!")
- else:
- print('No word pairs found!')
- if valid_pairs:
- print(f'The mirror words are:')
- print(f'{", ".join(valid_pairs)}')
- else:
- print('No mirror words!')
Add Comment
Please, Sign In to add comment