fork download
  1. def isSorted(x,flag):
  2. n=len(x)
  3. for i in range (n-1):
  4. if x[i+1]==x[i]:
  5. return False
  6. if sign(x[i+1]-x[i]) != flag:
  7. return False
  8. return True
  9.  
  10. def sign(a):
  11. if a>0:
  12. return 1;
  13. elif a<0:
  14. return -1;
  15. else:
  16. return 0
  17.  
  18.  
  19. print(isSorted([1,2,3,5,6,8],1))
  20. print(isSorted([1,2,2,5,6,8],1))
  21. print(isSorted([1,2,3,2,6,8],1))
  22. print(isSorted([7,6,5,4,3,-1],-1))
  23.  
  24.  
  25.  
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
True
False
False
True