Determine if a list is in descending order

前端 未结 7 2493
孤城傲影
孤城傲影 2020-12-03 17:35

I am trying to write a function that will test whether or not a list is in decending order. This is what I have so far, but it doesn\'t seem to be working for all lists. <

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 18:26

    You should rather do the reverse check (As soon as you get A[i] < A[i+1], return false

    def ordertest(A):
        for i in range( len(A) - 1 ):
            if A[i] < A[i+1]:
                return False
            return True
    

提交回复
热议问题