Added a Python implementation.