26 lines
1.6 KiB
Python
26 lines
1.6 KiB
Python
def get_region_by_county(county_name):
|
|
# Define the dictionary of regions and their associated counties/boroughs
|
|
regions = {
|
|
"Western New York": ["Niagara", "Erie", "Chautauqua", "Cattaraugus"],
|
|
"Finger Lakes": ["Orleans", "Genesee", "Wyoming", "Monroe", "Livingston", "Wayne", "Ontario", "Yates", "Seneca"],
|
|
"Southern Tier": ["Steuben", "Schuyler", "Chemung", "Tompkins", "Tioga", "Chenango", "Broome", "Delaware"],
|
|
"Central New York": ["Cortland", "Cayuga", "Onondaga", "Oswego", "Madison"],
|
|
"North Country": ["Saint Lawrence", "St Lawrence", "St. Lawrence", "Lewis", "Jefferson", "Hamilton", "Essex", "Clinton", "Franklin"],
|
|
"Mohawk Valley": ["Oneida", "Herkimer", "Fulton", "Montgomery", "Otsego", "Schoharie"],
|
|
"Capital District": ["Albany", "Columbia", "Greene", "Warren", "Washington", "Saratoga", "Schenectady", "Rensselaer"],
|
|
"Hudson Valley": ["Sullivan", "Ulster", "Dutchess", "Orange", "Putnam", "Rockland", "Westchester"],
|
|
"New York City": ["New York", "Manhattan", "Bronx", "Queens", "Kings", "Brooklyn", "Richmond", "Staten Island"],
|
|
"Long Island": ["Nassau", "Suffolk"]
|
|
}
|
|
|
|
# Trim any leading/trailing whitespace and convert to lowercase
|
|
county_name = county_name.strip().lower()
|
|
|
|
# Loop through the regions and check if the county is in any region's list
|
|
for region, counties in regions.items():
|
|
# Compare the county_name in lowercase with each county (also in lowercase)
|
|
if county_name in [county.lower() for county in counties]:
|
|
return region
|
|
|
|
# Return a message if the county is not found
|
|
return "Error" |