I have the following string:
points = "34.09352 -118.27483, 34.0914 -118.2758, 34.082 -118.2782, 34.0937 -118.2769, 34.0933 -118.2748"
points is a string that contains coordinate values (latitude & longitude) separated by commas.
I want to check that this string contains only integers or float values and that the first coordinate equals the last.
I have the following code for that:
def validate_points(points):
   coordinates = points.split(',')
   for point in coordinates:
      latlon = point.split(' ')
      latitude = latlon[0]
      longitude = latlon[1]
      if not is_number(latitude) or not is_number(longitude):
         raise WrongRequestDataError("Please, specify the correct type of points value. It must be a numeric value")
   first = coordinates[0]
   last = coordinates[len(coordinates) - 1]
   if first != last:
        raise WrongRequestDataError("Incorrect points format, the first point must be equal to last")
def is_number(s):
   try:
     if float(s) or int(s):
        return True
   except ValueError:
        return False
Is there any way to simplify or speed up this code?
 
     
     
     
     
     
    