Created
May 29, 2021 06:53
-
-
Save bharathmuddada/39919c58aaafad69ce355215f3ad5904 to your computer and use it in GitHub Desktop.
Second largest element in python
This file contains hidden or 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
| l=[10,5,28,6,35,29] | |
| def getSeclargest(l): | |
| if len(l)<= 1: | |
| return None | |
| lar=l[0] | |
| slar = None | |
| for x in l[1:]: | |
| if x > lar: | |
| slar =lar | |
| lar = x | |
| elif x !=lar: | |
| if slar == None or slar < x: | |
| slar = x | |
| return slar | |
| print(getSeclargest(l)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment