Python implementation of KSS