思路见此处
def get_mountain_peaks(height):
peak_count = 0
n = len(height)
if n == 0:#如果一个山高都没有,return 0
return 0
for i in range(1,n-1):
if height[i] > height[i-1] and height[i] > height[i+1]:
peak_count += 1
if height[0] > height[1] and n > 1:#边界情况
peak_count += 1
if height[-1] > height[-2] and n > 1:
peak_count += 1
print(peak_count)
def main():
height = list(map(int,input().strip("[]").split(",")))
get_mountain_peaks(height)
if __name__ =="__main__":
main()