Python solution to problem 2

Which I can't stand, but I want to move on.