the solution in python