这可能有助于:A=[10,9,8,3,1,0]
B=[1,9,18,33,41,50]
C=[1, 1, 1, 1, 1]
D= [1]
E=[1, 2, 3, 2, 1]
F =[]
def order(someList):
asc = True
desc = True
for idx in range(1, len(someList)):
if someList[idx] - someList[idx - 1] >= 0:
asc = asc & True
desc = desc & False
else:
desc = desc & True
asc = asc & False
if asc and not desc:
return "list is in ascending order"
elif desc and not asc:
return "list is in descending order"
else:
return "list is in no order"
print(order(A))
print(order(B))
print(order(C))
print(order(D))
print(order(E))
print(order(F))
执行时,此代码的输出为:list is in descending order
list