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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Python
  3. Regex and Parsing
  4. Validating Postal Codes
  5. Discussions

Validating Postal Codes

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 270 Discussions, By:

recency

Please Login in order to post a comment

  • lucasopoka
    1 week ago+ 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|
    Permalink
  • alessandromarco1
    3 weeks ago+ 0 comments
    regex_integer_in_range = r"^[1-9][0-9]{5}$"	
    regex_alternating_repetitive_digit_pair = r"(?=([\d])([\d])(\1))"
    
    0|
    Permalink
  • alessandromarco1
    3 weeks ago+ 0 comments
    regex_integer_in_range = r"^[1-9][0-9]{5}$"	
    regex_alternating_repetitive_digit_pair = r"(?=([\d])([\d])(\1))"
    
    0|
    Permalink
  • v_alishauskaite
    2 months ago+ 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)

    0|
    Permalink
  • Jabboscurio
    3 months ago+ 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)
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy