p = [5, 7, 3, 2, 4, 3, 7, 1] print [(i, p[i]) for i in range(len(p)) if p[max(0, i - 1)] >= p[i] <= p[min(len(p) - 1, i + 1)]] # alternative pp = [p[0]] + p + [p[-1]] print [(i - 1, pp[i]) for i in range(1, len(p) + 1) if pp[i - 1] >= pp[i] <= pp[i + 1]]
[(0, 5), (3, 2), (5, 3), (7, 1)] [(0, 5), (3, 2), (5, 3), (7, 1)]
It’s like finding when you feel beaten for nothing, no in or out, you just hang in there and don’t know what to do next.
However you know it could be temporary, but you never know next point would be lower or not.
Speaking by the code and Python is the only thing awesome here.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.