Question: def neighbors(map, r, c): Given a map and a location, there are up to eight possible locations immediately around it that might also exist on
def neighbors(map, r, c): Given a map and a location, there are up to eight possible locations immediately around it that might also exist on the map (unless we're along an edge or corner position). Build up a list of tuples, each tuple storing the (row, column) of the neighbors. They must be in order from lowest-row to later, lowest-column to later. This happens to mean the same ordering as they appear when the map is printed out. If the point isn't on the map, return an empty list.
Assume: map is a map as defined above, and r and c are int values.
neighbors(map1,1,1) [(0, 0), (0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1), (2, 2)]
neighbors(map2,0,3) [(0, 2), (0, 4), (1, 2), (1, 3), (1, 4)]
neighbors(map2,2,0) [(1, 0), (1, 1), (2, 1)]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
