Python implementation.