Skip to content

Instantly share code, notes, and snippets.

@laclefyoshi
Created October 4, 2012 00:07
Show Gist options
  • Save laclefyoshi/3830694 to your computer and use it in GitHub Desktop.
Save laclefyoshi/3830694 to your computer and use it in GitHub Desktop.
get indexies of local maximum values
#!/usr/bin/python
sample = [10, 11, 12, 1, 2, 3, 4, 2, 3]
temp = [0] + sample[0:-1]
points = map(lambda (x, y): x - 1,
            filter(lambda (i, v): v < 0,
                enumerate(map(lambda (a, b): a - b, zip(sample, temp)))))
if points[-1] != len(sample) - 1:
    points += [len(sample) - 1]
s = 0
for point in points:
    s += sample[point]
print s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment