Rewriting in python