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

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -