Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- string = input()
- valid_pairs = []
- mirror_pairs = []
- word_pairs = r"(@|#)(([A-Za-z]{3,})\1\1([A-Za-z]{3,}))\1"
- valid_match = re.search(word_pairs, string)
- if valid_match:
- match = re.findall(word_pairs, string)
- for m in match:
- valid_pairs.append(m[2])
- valid_pairs.append(m[3])
- print(f"{len(valid_pairs)//2} word pairs found!")
- for index in range(0, len(valid_pairs)-1, 2):
- if valid_pairs[index] == valid_pairs[index+1][::-1]:
- mirror_pairs.append(f"{valid_pairs[index]} <=> {valid_pairs[index+1]}")
- else:
- print("No word pairs found!")
- if mirror_pairs:
- print("The mirror words are:")
- print(", ".join(mirror_pairs))
- else:
- print("No mirror words!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement