Detecting Valid Latitude and Longitude Pairs

  • + 0 comments

    My code for Python (3)

    import re
    import sys
    data = sys.stdin.read()
    
    pattern=r'^\([\-\+]?(90(\.0{1,})?|(|[1-8][0-9]|[1-9])(\.[0-9]{1,})?)\,\s?[\-\+]?((180(\.0{1,})?|(|1[0-7][0-9]|[1-9][0-9]|[1-9])(\.[0-9]{1,})?))?\)$'
    
    for line in data.split("\n")[1:]:
        match = re.findall(pattern, line)
        print("Valid" if match else "Invalid")