An example of the Python implementation of the locateEmergency function is shown below
python
import csv
def locateEmergency(hospFile, polFile):
# Define the dictionary to store the data
emergency_data = {}
# Process hospital file
with open(hospFile, 'r') as hosp_csv:
hosp_reader = csv.reader(hosp_csv)
next(hosp_reader) # Skip the header row
for row in hosp_reader:
zip_code = row[-1]
emergency_type = row[0]
data = row[1:-1]
if zip_code not in emergency_data:
emergency_data[zip_code] = []
emergency_data[zip_code].append([emergency_type] + data)
# Process police file
with open(polFile, 'r') as pol_csv:
pol_reader = csv.reader(pol_csv)
next(pol_reader) # Skip the header row
for row in pol_reader:
zip_code = row[-1]
emergency_type = 'Police Station'
data = row[:-1]
if zip_code not in emergency_data:
emergency_data[zip_code] = []
emergency_data[zip_code].append([emergency_type] + data)
return emergency_data
# Example usage:
hospitals_file = 'hospitals.csv' # Replace with the actual file name
police_file = 'police_stations.csv' # Replace with the actual file name
result = locateEmergency(hospitals_file, police_file)
print(result)
So, the function above is one that reads the data from both files, organizes it by zip code, and returns a dictionary with zip codes as keys and a 2D list of emergency facilities for each zip code as values.