fork download
  1. test_cases = [[True], [False],
  2. [True, False],
  3. [True, False, False],
  4. [True, True, True, False],
  5. [False, True],
  6. [True, False, True]]
  7.  
  8. expected_output = [True, True, True, True, True, False, False]
  9.  
  10.  
  11. def check0(x):
  12. n_trues = sum(x)
  13. should_be_true = x[:n_trues] # get the first n items
  14. should_be_false = x[n_trues:len(x)] # get the remaining items
  15. # return True only if all of the first n elements are True and the remaining
  16. # elements are all False
  17. return all(should_be_true) and all([not element for element in should_be_false])
  18.  
  19.  
  20. def check1a(x):
  21. status = list(k for k, g in groupby(x))
  22. return len(status) <= 2 and (status[0] is True or status[-1] is False)
  23.  
  24.  
  25. def check1b(x):
  26. status = list(k for k, g in groupby(map(book, x)))
  27. return status and len(status) <= 2 and (status[0] or not status[-1])
  28.  
  29.  
  30. def check1c(x):
  31. status = list(k for k, g in groupby(map(book, x)))
  32. return not status or (len(status) <= 2 and (status[0] or not status[-1]))
  33.  
  34.  
  35. def check2(x):
  36. iterator = iter(x)
  37. # process the true elements
  38. all(iterator)
  39. # check that there are no true elements left
  40. return not any(iterator)
  41.  
  42.  
  43. assert list(map(check0, test_cases)) == expected_output
  44. assert list(map(check1a, test_cases)) == expected_output
  45. assert list(map(check1b, test_cases)) == expected_output
  46. assert list(map(check1c, test_cases)) == expected_output
  47. assert list(map(check2, test_cases)) == expected_output
Success #stdin #stdout 0.03s 27704KB
stdin
Standard input is empty
stdout
Standard output is empty