Minor adjustment to Python's solution to problem 3