Added python implementation with tests