Example code to article at http://www.lifeofatechdude.com/2014/03/generator-function-in-python.html