Rewrite in Python