Python implementation of wpm1 algorithm