added python implementation