Tidy up Problem 25, Python