rewrite with Python