Validating Postal Codes
Validating Postal Codes
2. must not contain more than one alternating repetitive digit pair.
Alternating repetitive digits are digits which repeat immediately after the next digit. In other
words, an alternating repetitive digit pair is formed by two equal digits that have just a single
For example:
string.
Both these regular expressions will be used by the provided code template to check if the
(bool(re.match(regex_integer_in_range, P))
and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)
Input Format
Locked stub code in the editor reads a single string denoting from stdin and uses provided
Output Format
You are not responsible for printing anything to stdout. Locked stub code in the editor does
that.
Sample Input 0
110000
Sample Output 0
False
Explanation 0
1 1 0000 : (0, 0) and (0, 0) are two alternating digit pairs. Hence, it is an invalid postal code.
Note:
Change Theme
Python 3
1
2
3
4 Line:
M 1 Col: 1
regex_integer_in_range = r"_________" # Do
Submit Code
onot delete 'r'.
Run Code
regex_alternating_repetitive_digit_pair
rUpload Code as File =
Test against custom input
r"_________" # Do not delete 'r'.
e
Blog
Scoring
Environment
FAQ
About Us
Support
Careersimport re
# Regular expressions
regex_integer_in_range = r"^[1-9][0-9]{5}$"
regex_alternating_repetitive_digit_pair = r"(\d)(\d)\1"
# Sample input
P = input().strip()
# Validate postal code
is_valid = bool(re.match(regex_integer_in_range, P)) and
len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2
# Output result
print(is_valid)
Terms Of Service
Privacy Policy
solution !!!!!
import re
# Regular expressions
regex_integer_in_range = r"^[1-9][0-9]{5}$"
regex_alternating_repetitive_digit_pair = r"(\d)(\d)\1"
# Sample input
P = input().strip()
# Validate postal code
is_valid = bool(re.match(regex_integer_in_range, P)) and
len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2
# Output result
print(is_valid)