Python 3 version of the code featured on this website