a='X X\n X \nX X' n=a[3] exec("b=a.replace(*'X ');a,b=a.split(n),b.split(n);a=n.join(map(n.join,[map(''.join,k)for k in zip(a,b,a),zip(b,a,b),zip(a,b,a)]));"*3) print a
Note that non-ascii characters in the above source code will be escaped (such as \x9f).