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

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -