Geting towns within the location between two point, that is latitude and longitude. Below is my code but am not getting the intended out put

list_of_dict =

with open(“uk-towns-sample.csv”, “r”) as file:

towns_reader = csv.DictReader(file)

for town in towns_reader:

    town["easting"] = int(town["easting"])

    town["northing"] = int(town["northing"])

    town["latitude"] = float(town["latitude"])

    town["longitude"] = float(town["longitude"])

    town["elevation"] = int(town["elevation"])

    list_of_dict.append(town)

def cities_between_long_lat(coordinates, list_of_dict):

list_of_towns = []

for town in list_of_dict:

     if  coordinates[0]["lat"] < town["latitude"]:

         if coordinates[1]["lat"] < town["latitude"]:

             if coordinates[0]["long"] <  town["longitude"]:

                if coordinates[1]["long"] < town["longitude"]:

                   list_of_towns.append(town["name"])                              

return list_of_towns

Do you want both coordinates to be less than the longitude? If you want it to be between them instead, I’d probably write something similar to:

if (coordinates[0]["lat"] <= town["latitude"] <= coordinates[1]["lat"] and
    coordinates[0]["long"] <= town["longitude"] <= coordinates[1]["long"]):
    list_of_towns.append(town["name"])

The idea is i want to get the towns within my coordinates. Let me try what you’ve proposed. Thank you.