python - Recursively Identifying Sorted Lists -


as recursion practice exercise, writing python function recursively identifies if input list sorted least greatest, real numbers only, , returns boolean value.

my code is:

def det_sorted(lista):     if len(lista) == 1:         return(true)     else:         if lista[0] <= det_sorted(lista[1:]):             return(true)         elif lista[0] > det_sorted(lista[1:]):             return(false) 

this function returns 'false.' general question: how iterate recursively through list correctly? specific question: have done wrong here?

you close , want call recursion return

else:         if lista[0] <= lista[1]:              return sorted(lista[1:]) 

or combine both statements return (and rid of else)

return  lista[0] <= lista[1] , sorted(lista[1:]) 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -