I am trying to define a function called isSorted that should take a list as an argument an return True if it is sorted and False if it is not sorted. I've tried to look up videos for help and haven't found any relevant ones. The problem I am having is how to check the value of an index against the previous one to see if it is larger. Can anyone give me an idea on how to do this?
def isSorted(list): previous_number = 0 for i in list: value = list[i] if value - previous_number >= 0: previous_number = list[i] return True else: return False lyst = [1,2,3,4,5,6,7,8,9] isSorted(lyst)this is what I have come up with but when I print it out it is always true, even when i make the list unsorted.