Second largest number in list python
- by Manu Lakaster
So I have to find THE SECOND LARGEST NUMBER IN A LIST. I am doing it through simple loops.My approach is I am going to divide a list into two parts and then find the largest number into two parts and then compare two nuumbers. I will choose the smaller number from two of them. I can not use ready functions or different approaches.
Basically, this is my code....But it does not run correctly....Help me please to fix it because I spent a lot of time on it :( Thanks....P.S. Can we use indices to "divide" a list
???
#!/usr/local/bin/python2.7
alist=[-45,0,3,10,90,5,-2,4,18,45,100,1,-266,706]
largest=alist[0]
h=len(alist)/2
m=len(alist)-h
print(alist)
for i in alist:
if alist[h]>largest:
largest=alist[h]
i=i+1
print(largest)