Python solution.