Python 3 while loop not fully looping? -


this question has answer here:

so i've been @ while. i'm trying create function checks if numbers in list increasing. example [1, 2, 3] true [1, 3, 2] false. have gotten point [1, 2, 3] true, [3, 2, 1] false, [1, 3, 2] still true. assume because first 2 positions being read?

here function reference:

 def increasing(lst):     index = 0     index2 = index + 1     while index < len(lst):         if lst[index] >= lst[index2]:             index += 1             index2 += 1             return false         else:             while index < len(lst):                 if lst[index] < lst[index2]:                     index += 1                     index2 += 1                     return true 

try this:

def increasing(lst):     return lst == sorted(lst) 

this checks whether list sorted.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -