def borders(district, unit):
    """Check if a unit borders a district."""
    if district == []:
        return True
    neighbour_coords = [(unit.x+i, unit.y+j) for i in [1, 0, -1]
                        for j in [1, 0, -1] if bool(i) ^ bool(j)]
    district_coords = [(d_unit.x, d_unit.y) for d_unit in district]
    return bool([i for i in neighbour_coords if i in district_coords])