Replace the PHP solution with one written in Python.