Created
November 30, 2019 11:59
-
-
Save volf52/b7134b987315f57ddc1c00abdb2f3293 to your computer and use it in GitHub Desktop.
Second highest number in array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def second_highest(iterable, key = lambda x: x): | |
highest = -1 | |
second = -1 | |
for i in iterable: | |
o = key(i) | |
if(o > highest): | |
second, highest = highest, o | |
elif(o > second): | |
second = o | |
return second |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment