# Detecting Valid Latitude and Longitude Pairs – HackerRank Solution

In this post, we will solve Detecting Valid Latitude and Longitude Pairs HackerRank Solution. This problem (Detecting Valid Latitude and Longitude Pairs) is a part of HackerRank Regex series.

## Detecting Valid Latitude and Longitude Pairs – HackerRank Solution

### Python

```import re
p = re.compile('([+-]*\d*[\.]*\d*), ([+-]*\d*[\.]*\d*)')
t = int(input())
for i in range(t):
try:
z = str(input())
z = z[1:len(z)-1]
zz = re.findall(p, z)
zz = zz
x = zz
y = zz
if(x == '+' or x == '-'):
x = x[1:]
if(y == '+' or y == '-'):
y = y[1:]
if(x[len(x)-1] == '.' or y[len(y)-1] == '.'):
print("Invalid")
continue
if((len(x) > 1 and x == '0' and x != '.') or (len(y) > 1 and y == '0' and y != '.')):
print("Invalid")
continue
x = float(x)
y = float(y)
if(x >= -90.0 and x <= 90.0 and y >= -180.0 and y <= 180.0):
print("Valid")
else:
print("Invalid")
except:
print("Invalid")
```

Note: This problem (Detecting Valid Latitude and Longitude Pairs) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.