for loop: range() result has too many items
apt.shansen at gmail.com
Tue Oct 13 23:53:47 CEST 2009
On Tue, Oct 13, 2009 at 2:17 PM, Peng Yu <pengyu.ut at gmail.com> wrote:
> The following code does not run because range() does not accept a big
> number. Is there a way to make the code work. I'm wondering if there
> is a way to write a for-loop in python similar to that of C style.
> for(int i = 0; i < a_big_number; ++ i)
Don't use range(); range creates allocates an entire list-- thus its quite
expensive for big numbers.
Use xrange instead, which generates one number at a time as its consumed.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list