Python implementation of SINGLE algorithm