def _by_proximity(ambulances, location): # TODO: Refactor - generalize ( move to map ) ambulance_distances = [(CityMap.get_distance(ambulance.location, location), ambulance) for ambulance in ambulances] ambulance_distances.sort(key=lambda x: x[0]) return [tpl[1] for tpl in ambulance_distances]
def _by_proximity(units, location): policemen_distances = [ (CityMap.get_distance(policeman.location, location), policeman) for policeman in units ] policemen_distances.sort(key=lambda x: (x[0], -x[1].efficiency)) return [tpl[1] for tpl in policemen_distances]