python implementation of the challenge