In: Computer Science
def compare_elevations_within_row(elevation_map:
List[List[int]], map_row: int, level: int) -> List[int]:
"""Return a new list containing the three counts: the number
of
elevations from row number map_row of elevation map
elevation_map
that are less than, equal to, and greater than elevation level.
Precondition: elevation_map is a valid elevation map.
0 <= map_row < len(elevation_map).
>>> compare_elevations_within_row(THREE_BY_THREE, 1,
5)
[1, 1, 1]
>>> compare_elevations_within_row(FOUR_BY_FOUR, 1,
2)
[0, 1, 3]
"""
for i in elevation_map[map_row]:
differences=[0,0,0]
if i<level:
differences[0] += 1
elif i==level:
differences[1] += 1
else:
differences[2] += 1
return differences
This was written in python, I am wondering why does the header of the function shows syntax error starting from List. (List[List[int]], map_row: int, level: int) -> List[int]:)these are all underedline
# do comment if any problem arises
# Code
# you are missing this import
from typing import List
def compare_elevations_within_row(elevation_map: List[List[int]], map_row: int, level: int) -> List[int]:
"""Return a new list containing the three counts: the number of
elevations from row number map_row of elevation map elevation_map
that are less than, equal to, and greater than elevation level.
Precondition: elevation_map is a valid elevation map.
0 <= map_row < len(elevation_map).
>>> compare_elevations_within_row(THREE_BY_THREE, 1, 5)
[1, 1, 1]
>>> compare_elevations_within_row(FOUR_BY_FOUR, 1, 2)
[0, 1, 3]
"""
for i in elevation_map[map_row]:
differences = [0, 0, 0]
if i < level:
differences[0] += 1
elif i == level:
differences[1] += 1
else:
differences[2] += 1
return differences
Screenshot:
