The way of implementing iterators are known as generators. It is a normal function except that it yields expression in the function.
Since Python 2.2, generators provide an elegant way to write simple and efficient code for functions that return a list of elements.