+ 4

Please help me solve this question.(In Python)

Define the function check_location(coordinate, maplist, legend) that takes in a tuple coordinates, a list of lists maplist, and a dictionary legend. Return the meaning of the symbol found at row and column, making use of the legend. If the symbol is not found in legend, return "unknown". For example, check_location((0,1), [["#", "#"],["#", " "]], {" ": "path", "#": "blocked"}) should return "blocked". For example, check_location((1,0), [["#"],["z"]], {" ": "path", "#": "blocked"}) should return "unknown".

15th Oct 2017, 8:55 AM
Damaen
Damaen - avatar
2 Answers
0
# code by siva shankar #crd for coordinates def check_location (crd, maplist ,legend): # assuming two dimensional coordinates val=maplist[crd[0]][crd[1]] try : legend [val] != None return legend [val] except KeyError: return "unknown" a1=check_location((0,1),[['#','#'],['#',' ']],{' ':'path','#':'blocked'}) print (a1) a2=check_location((1,0),[['#'],['z']],{' ':'path','#':'blocked'}) print (a2)
15th Oct 2017, 10:07 AM
Siva Shankar
Siva Shankar - avatar
0
Added check for valid coordinates also. Pls check https://code.sololearn.com/co8x1V944Ud7/?ref=app
15th Oct 2017, 10:20 AM
Siva Shankar
Siva Shankar - avatar