can you rewrite the code in python?