Problem 44 Python solution.