Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- pattern = r'(?P<first_sep>!)(?P<command>[A-Z][a-z]{2,})(?P=first_sep):\[(?P<message>[a-zA-Z]{8,})\]'
- n = int(input())
- for _ in range(n):
- text = input()
- matches = list(re.finditer(pattern, text))
- if len(matches) > 0:
- for el in matches:
- nums = []
- for char in el.group('message'):
- nums.append(str(ord(char)))
- text_to_print = el.group("command")+': '+' '.join(nums)
- print(text_to_print)
- else:
- print(f'The message is invalid')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement