嗨,所以我想对我的函数进行编程,该函数采用一个嵌套列表,一个数字选择一个行,然后一个特定的数字。因此,其假设要做的是接收3个参数height_map(一个嵌套列表),map_row(选择行)和level(一个int)。并返回特定行小于,等于和大于级别的次数。
因此,现在我创建了一个循环,该循环将遍历嵌套列表的特定行,并且我尝试遍历每个数字,查看其是否小于,等于和大于作为第三个参数的级别并返回它
示例是compare_elevations_within_row(THREE_BY_THREE,1,5), THREE_BY_THREE = [[1、2、1],[4、6、5],[7、8、9] 它返回[1,1,1]
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.
>>> compare_elevations_within_row(THREE_BY_THREE,5)
[1,1]
THREE_BY_THREE = [[1,2,1],[4,6,5],[7,8,9]]
"""
num = elevation_map[map_row]
count = []
for index in num:
if index < level:
count[0] = count + 1
elif index== level:
count[1] = count + 1
else:
count[2] = count + 1
return count