Refacor Py problem 4