Recursive function to return largest element in a list

Asked

Viewed 28 times

-2

Recursive function that receives a lista and return the highest value from that list.

def maior(lista):
    maior=0
    if len(lista)==0:
        return lista
    elif len(lista)==1:
        return lista
    else:
      for i in lista:
        if lista[0]> maior:
           maior=lista[0]
           return maior

lista=[-1,0,1,2,3]
  • The question suggested above in the blue box is not 100% identical, because there returns the largest and smallest, but it is not difficult to adapt the code to return only the largest (in the background, the general idea is the same)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.