We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Validating Postal Codes
Validating Postal Codes
+ 0 comments regex_integer_in_range = r'^[1-9][0-9]{5}$' regex_alternating_repetitive_digit_pair = r'(\d)(?=.\1{1})' import re P = input() print (bool(re.match(regex_integer_in_range, P)) and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)
+ 0 comments regex_integer_in_range = r"^[1-9][0-9]{5}$" regex_alternating_repetitive_digit_pair = r"(?=([\d])([\d])(\1))"
+ 0 comments regex_integer_in_range = r"^[1-9][0-9]{5}$" regex_alternating_repetitive_digit_pair = r"(?=([\d])([\d])(\1))"
+ 1 comment This statement doesn't look right to me:
len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)
It should be replaced with:
len(re.findall(regex_alternating_repetitive_digit_pair, P)) == 0)
Try running you code against this one: 454286. (Corrected)
+ 1 comment regex_integer_in_range = r"^[1-9]{1}[0-9]{5}$" regex_alternating_repetitive_digit_pair = r"(\d)(?=\d\1)" import re P = input() print (bool(re.match(regex_integer_in_range, P)) and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)
Load more conversations
Sort 270 Discussions, By:
Please Login in order to post a comment