Infinite lists and generators
phr-n2001d at nightsong.com
Wed Nov 14 10:29:59 CET 2001
Luigi Ballabio <ballabio at mac.com> writes:
> I've been reading a few back issues of the Perl Journal, and I
> came across an article on implementing infinite lists in Perl. Just
> for fun I went ahead and reimplemented it in Python---I know someone
> probably did already, but as I said, it was for fun. Also, I've
> written a test suite which showcases a few tricks such as building the
> list of all prime numbers, of the Hamming numbers, and the power
> series of exp, sin and cos. I'm including the file below.
> My question is: how does one go about pulling such stunts with
> generators instead?
You might like to read the book Structure and Interpretation of
Computer Programs, by Abelson and Sussman. The entire text is online at:
The programs in the book are in Scheme, but it develops a whole series
of programs in the style you're describing.
More information about the Python-list