In [1]: a = [1, 2, 3, 5, 4, 2, -1, 2, 6, 8, 10, 8, 7, 6]
In [2]: [x for i, x in enumerate(a) if i != 0 and i != len(a)-1 and ( (x > a[i-1] and x > a[i+1]) or (x < a[i-1] and x < a[i+1]) )]
Out[2]: [5, -1, 10]
【 在 formydream (xXx) 的大作中提到: 】
: 比如 1 2 3 5 4 2 -1 2 6 8 10 8 7 6
: 对这个序列得到他的三个极值点5,-1,10
--
FROM 112.10.90.*