Implemented the Python version.