o=t=[]for i in input():o+=~i%2*(t+[i]);t=i%2*([i]+t)print o+t
[123,123,345,0,1,9]
[345, 123, 123, 0, 9, 1]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!