fork(1) download
  1. def is_sorted(check):
  2. ascending = True
  3. descending = True
  4. previous = check[0]
  5. for item in check[1:]:
  6. if ascending and item < previous:
  7. ascending = False
  8. if descending and item > previous:
  9. descending = False
  10. if not ascending and not descending:
  11. return False
  12. previous = item
  13. return True
  14.  
  15. def test(check):
  16. whether = is_sorted(check)
  17. print(whether, check)
  18.  
  19. test([1, 2, 3, 4])
  20. test([1, 1, 1, 1])
  21. test([9, 8, 7, 6])
  22. test([1, 2, 3, 2])
Success #stdin #stdout 0.02s 7344KB
stdin
Standard input is empty
stdout
(True, [1, 2, 3, 4])
(True, [1, 1, 1, 1])
(True, [9, 8, 7, 6])
(False, [1, 2, 3, 2])