Try to write a python implementation