You need to create a function that will validate if given parameters are valid geographical coordinates.

Valid coordinates look like the following: __"23.32353342, -32.543534534"__.
The return value should be either __true__ or __false__.

Latitude (which is first float) can be between 0 and 90, positive or negative.
Longitude (which is second float) can be between 0 and 180, positive or negative.

Coordinates can only contain digits, or one of the following symbols (including space after comma) __ -, . __

There should be no space between the minus "-" sign and the digit after it.

Here are some valid coordinates:

* -23, 25
* 24.53525235, 23.45235
* 04, -23.234235
* 43.91343345, 143
* 4, -3

And some invalid ones:

* 23.234, - 23.4234
* 2342.43536, 34.324236
* N23.43345, E32.6457
* 99.234, 12.324
* 6.325624, 43.34345.345
* 0, 1,2
* 0.342q0832, 1.2324

Difficulty: introductory

Starter code:

def is_valid_coordinates(coordinates):
	

Solutions:
def is_valid_coordinates(coordinates):
    try:
        lat, lng = [abs(float(c)) for c in coordinates.split(',') if 'e' not in c]
    except ValueError:
        return False

    return lat <= 90 and lng <= 180

import re

def is_valid_coordinates(coordinates):
    return bool(re.match("-?(\d|[1-8]\d|90)\.?\d*, -?(\d|[1-9]\d|1[0-7]\d|180)\.?\d*$", coordinates))

def is_valid_coordinates(s):
    try:
        a, b = s.split(',')
        if 'e' in a or 'e' in b: raise Exception
        a, b = float(a), float(b)
        return abs(a)<=90 and abs(b)<=180
    except:
        return False


import re

COORD_RE = re.compile(r'(-?[\d]+\.?[\d]*), ?(-?[\d]+\.?[\d]*)$')
    
def is_valid_coordinates(coordinates):
    match = COORD_RE.match(coordinates)
    if not match: return False
    x, y = match.group(1), match.group(2)
    
    x, y = float(x), float(y)
    if not 0 <= abs(x) <= 90: return False
    if not 0 <= abs(y) <= 180: return False
    
    return True

def is_valid_coordinates(coordinates):
    print(coordinates)
    for char in coordinates:
        if not (char.isdigit() or char in ['-', '.', ',', ' ']):
            return False
    l = coordinates.split(", ")
    if len(l) != 2:
        return False
    print(l)
    try:
        latitude = float(l[0])
        longitude = float(l[1])
    except:
        return False
    print(latitude, longitude)
    return -90 <= latitude <= 90 and -180 <= longitude <= 180

def is_valid_coordinates(coordinates):
    coords = coordinates.split(',')
    if len(coords) != 2 or 'e' in coordinates:
        return False
    for i,coord in enumerate(coords):
        try:
            coord = float(coord)
            if (i == 0 and abs(coord) > 90) or (i == 1 and abs(coord) > 180):
                return False
        except:
            return False
    return True

def is_valid_coordinates(coordinates):
    # all characters to be used
    digits = ["1","2","3","4","5","6","7","8","9","0"]
    dec = "."
    comma = ","
    space = " "
    neg = "-"
    
    # counters
    negOK, digitOK = True, True
    decOK, spaceOK, commaOK = False, False, False
    hitComma = False
    hitDec = False
    
    for c in coordinates:
        print(c)
        if hitComma:
            commaOK = False
        if c in digits:
            if not digitOK:
                return False
            if not hitDec:
                decOK = True
            commaOK = True
            negOK = False
            continue
        elif c == neg:
            if not negOK:
                return False
            negOK, commaOK, decOK, spaceOK = False, False, False, False
            continue
        elif c == dec:
            if not decOK:
                return False
            negOK, commaOK, decOK, spaceOK = False, False, False, False
            digitOK = True
            hitDec = True
            continue
        elif c == comma:
            if not commaOK:
                return False
            negOK, commaOK, decOK, digitOK = False, False, False, False
            spaceOK = True
            continue
        elif c == space:
            if not spaceOK:
                return False
            negOK, digitOK = True, True
            decOK, spaceOK, commaOK = False, False, False
            hitComma = True
            hitDec = False
            continue
        return False
    
    # now check the size of the coordinates
    cArr = coordinates.split(", ")
    if abs(float(cArr[0])) > 90 or abs(float(cArr[1])) > 180:
        return False
    return True

def is_valid_coordinates(coordinates):
    x = coordinates.split(', ')
    try:
        if len(x) == 2 and 90 >= float(x[0]) >= -90 and 180 >= float(x[1]) >= -180 and not any(c.isalpha() for c in x[0]) and not any(c.isalpha() for c in x[1]):
            return True
    except: 
        return False
    return False

def is_valid_coordinates(c):
    try: return all(-r <= float(s) <= r and 'e' not in s for s,r in zip(c.split(','), [90,180,-1]))
    except ValueError: return False

def is_valid_coordinates(coordinates):
    valid_chars = set('0123456789-.')
    try:
        latitude, longitude = (abs(float(a)) for a in coordinates.split(', ')
                               if valid_chars.issuperset(a))
    except ValueError:
        return False
    return latitude <= 90 and longitude <= 180