Re: for loop: range() result has too many items

2009-10-15 Thread Tim Roberts
Matt Nordhoff wrote: > >That's what itertools.count() is for. > > > >It'll be faster, too, since it's written in C. Not that it really >matters, but it's always nice. For being such a simple concept, I've been surprised how many place

Re: for loop: range() result has too many items

2009-10-15 Thread Mark Dickinson
On Oct 15, 8:39 pm, David C. Ullrich wrote: > >For what it's worth, there *is* a Python oddity lurking > >under the surface here, at least for 64-bit.  Here's > >Python 2.6 on a 64-bit machine: > > Is that a 64-bit Python as well? Yes. Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: for loop: range() result has too many items

2009-10-15 Thread David C . Ullrich
On Wed, 14 Oct 2009 01:54:44 -0700 (PDT), Mark Dickinson wrote: >On Oct 13, 10:39 pm, Steven D'Aprano > wrote: >> On Tue, 13 Oct 2009 16:17:58 -0500, Peng Yu wrote: >> > Hi, >> >> > The following code does not run because range() does not accept a big >> > number. >> >> Incorrect. >> >> >>> range

Re: for loop: range() result has too many items

2009-10-14 Thread Mark Dickinson
On Oct 13, 10:39 pm, Steven D'Aprano wrote: > On Tue, 13 Oct 2009 16:17:58 -0500, Peng Yu wrote: > > Hi, > > > The following code does not run because range() does not accept a big > > number. > > Incorrect. > > >>> range(sys.maxint+2, sys.maxint+5) > > [2147483649L, 2147483650L, 2147483651L] For

Re: for loop: range() result has too many items

2009-10-13 Thread Matt Nordhoff
Matt Nordhoff wrote: > Andre Engels wrote: > [snip] > >> However, I think that the better Python way would be to use a generator: >> >> def infinite_numbergenerator(): >> n = 0 >> while True: >> yield n >> n += 1 >> >> for i in infinite_numbergenerator(): >> ... > >

Re: for loop: range() result has too many items

2009-10-13 Thread Matt Nordhoff
Andre Engels wrote: [snip] > However, I think that the better Python way would be to use a generator: > > def infinite_numbergenerator(): > n = 0 > while True: > yield n > n += 1 > > for i in infinite_numbergenerator(): > ... That's what itertools.count() is for.

Re: Re: for loop: range() result has too many items

2009-10-13 Thread Dave Angel
Andre Engels wrote: On Tue, Oct 13, 2009 at 11:55 PM, Andre Engels wrote: for i in range(sys.maxint): if i % 100 =0: print i Grmbl cut-and-paste error... I meant of course: for i in xrange(sys.maxint): if i % 100 =0: print i What version of Python gives a

Re: for loop: range() result has too many items

2009-10-13 Thread Rhodri James
On Tue, 13 Oct 2009 22:17:58 +0100, Peng Yu 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. xrange() Have you read the document

Re: for loop: range() result has too many items

2009-10-13 Thread Andre Engels
On Tue, Oct 13, 2009 at 11:55 PM, Andre Engels wrote: > for i in range(sys.maxint): >    if i % 100 == 0: >       print i Grmbl cut-and-paste error... I meant of course: for i in xrange(sys.maxint): if i % 100 == 0: print i -- André Engels, andreeng...@gmail.com -- http://mail.p

Re: for loop: range() result has too many items

2009-10-13 Thread Andre Engels
On Tue, Oct 13, 2009 at 11:17 PM, Peng Yu wrote: > Hi, > > 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_

Re: for loop: range() result has too many items

2009-10-13 Thread Stephen Hansen
On Tue, Oct 13, 2009 at 2:17 PM, Peng Yu wrote: > Hi, > > 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_

Re: for loop: range() result has too many items

2009-10-13 Thread Steven D'Aprano
On Tue, 13 Oct 2009 16:17:58 -0500, Peng Yu wrote: > Hi, > > The following code does not run because range() does not accept a big > number. Incorrect. >>> range(sys.maxint+2, sys.maxint+5) [2147483649L, 2147483650L, 2147483651L] > Is there a way to make the code work. I'm wondering if there

Re: for loop: range() result has too many items

2009-10-13 Thread Mel
Peng Yu wrote: > Hi, > > 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) > > Regards, > Pe

for loop: range() result has too many items

2009-10-13 Thread Peng Yu
Hi, 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) Regards, Peng $ cat for_loop.py import sys de