Convert notebook solution from ex 3 to pure pyhthon.