[pydotorg-www] Wiki Edit on `Generators Page'
B.V. Raghav
bvraghav at iitk.ac.in
Wed Apr 20 08:04:21 EDT 2016
Hi,
Edit suggestion on the following page:
https://wiki.python.org/moin/Generators
> Here, we compose a square generator with the takewhile generator, to generate squares less than 100
> Toggle line numbers
> #add squares less than 100
> square = (i*i for i in count())
> bounded_squares = takewhile(lambda x : x< 100, square)
> total = 0
> for i in bounded_squares:
> total += i
The above example requires an import of itertools. Hence I suggest the
following addition preceding the example:
> from itertools import count, takewhile
It took me a while to search this out in google! Being a newbie, I feel
that the aforementioned amendment smoothens my uphill learning curve.
Thanks,
r
--
(B.V. Raghav)
More information about the pydotorg-www
mailing list