added python implementation.