fork(6) download
  1. def f(x):
  2. i=j=0
  3. for n in x+[0]:
  4. if~n%2:x[i:j]=x[i:j][::-1];i=j+1
  5. j+=1
  6.  
  7. for x in ([0, 1], [1, 3], [1, 2, 3], [1, 3, 2], [10, 7, 9, 6, 8, 9], [23, 12, 32, 23, 25, 27], [123, 123, 345, 0, 1, 9]):
  8. f(x)
  9. print x
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
[0, 1]
[3, 1]
[1, 2, 3]
[3, 1, 2]
[10, 9, 7, 6, 8, 9]
[23, 12, 32, 27, 25, 23]
[345, 123, 123, 0, 9, 1]