Updated Python solution to problem 111