python - Finding 3rd Lowest Value Without Sort -


so i'm tasked finding third lowest value of given list. code looks like

def findminindex(l, startindex):     minindex = startindex     currindex = minindex + 1     while currindex < len(l):         if l[currindex] < l[minindex]:             minindex = currindex             currindex = currindex + 1     return minindex  def thirdsmallest(l):     = 0     while < len(l):          minindex = findminindex(l, i)         l[i], l[minindex] = l[minindex], l[i]         = + 1     print(l[2])   thirdsmallest([1, 99, 7, -3, 3, 10, 12]) 

the list have l should print 3 3rd lowest value, anaconda taking incredibly long time return me. given hint should modify

while < len(l): 

or print function. dont see should do. advice?

i don't understand want do, i've find 1 error, leading potential infinite loop:

def findminindex(l, startindex):     minindex = startindex     currindex = minindex + 1     while currindex < len(l):         if l[currindex] < l[minindex]:             minindex = currindex         currindex = currindex + 1  # error corrected here     return minindex 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -