edit solution2's code to python