Method returning an Iterable Object

Andreas Waldenburger geekmail at usenot.de
Mon Jan 26 20:28:04 CET 2009


On Tue, 27 Jan 2009 00:05:53 +0530 Anjanesh Lekshminarayanan
<mail at anjanesh.net> wrote:

> > You can also replace the whole class with a function thusly:
> >
> >    def two_times(n):
> >        for k in itertools.count(1):
> >            yield n * (2**k)
> >
> > This function is then called a generator (because it generates an
> > iterator). You can now say
> >
> >    infinitely_doubling_numbers = two_times(2)
> >    for number in in infinitely_doubling_numbers:
> >        print number
> 
> Oh..this is new. Will checkup itertools. Thanks.
> 
OK, happy I could help. But my point was the yield statement (in case
you didn't know about yield).

regards
/W

-- 
My real email address is constructed by swapping the domain with the
recipient (local part).



More information about the Python-list mailing list