add a python version implemented by heap