My platform - Mepis Linux, kernel 2.6.4 , Pentium III
I tested generator expressions by using the following
statement (which finds the sum of a range of numbers) -
sum(a for a in range(1, 123))
As can be seen in the output below, this works fine
for small values of a. However, it gives an
OverflowError for large values of a.
********* Start of output
*******************************************
Python 2.4a3 (#1, Sep 5 2004, 15:03:34)
[GCC 3.3.3 (Debian 20040429)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> sum(a for a in range(1, 123))
7503
>>> sum(a for a in range(1, 999999999999999))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: range() result has too many items
>>>
*********** End of output
*********************************************
|