2.2 features

David Bolen db3l at fitlinxx.com
Wed Jul 25 23:03:57 CEST 2001


Jeff Shannon <jeff at ccvcorp.com> writes:

> Haven't looked into this in detail, or even downloaded 2.2 yet, but...

It's sort of noticeable from the question :-)

> couldn't that be written as:
> 
> if __name__ == '__main__':
>     for i in fib():
>         print i,
> 
> ???

Only if fib() was going to return the entire list of numbers in the
sequence as an already created list object.  But fibonacci numbers are
an infinite sequence, so clearly you can't do that.  Or you'd have to
artifically terminate it somewhere.

The generator gives you the ability to create an object that works
like and can be used as an iterator, but supporting an easy to
implement (as a function) incremental approach to generating the
values of the sequence.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list