working python soln