Python Pairtree implementation