Skip to content

Instantly share code, notes, and snippets.

@bharathmuddada
Created May 29, 2021 06:53
Show Gist options
  • Select an option

  • Save bharathmuddada/39919c58aaafad69ce355215f3ad5904 to your computer and use it in GitHub Desktop.

Select an option

Save bharathmuddada/39919c58aaafad69ce355215f3ad5904 to your computer and use it in GitHub Desktop.
Second largest element in python
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