begin Python implementation