Re: [Tutor] range efficiency

2013-05-12 Thread eryksun
On Sat, May 11, 2013 at 10:41 PM, Danny Yoo wrote: > On Fri, May 10, 2013 at 3:19 PM, Jim Mooney wrote: >> If I'm using a variable-dependent range in a for loop, is Python smart >> enough to figure the variable once so I don't have to hoist it up? > > The gritty details say "yes": > > http://

Re: [Tutor] range efficiency

2013-05-11 Thread Danny Yoo
On Fri, May 10, 2013 at 3:19 PM, Jim Mooney wrote: > If I'm using a variable-dependent range in a for loop, is Python smart > enough to figure the variable once so I don't have to hoist it up? Hi Jim, The gritty details say "yes": http://docs.python.org/2/reference/compound_stmts.html#the-

Re: [Tutor] range efficiency

2013-05-11 Thread eryksun
On Fri, May 10, 2013 at 5:19 PM, Jim Mooney wrote: > If I'm using a variable-dependent range in a for loop, is Python smart > enough to figure the variable once so I don't have to hoist it up? At the start of a for loop, the interpreter gets an iterator for the iterable. The latter is evaluated

Re: [Tutor] range efficiency

2013-05-10 Thread Steven D'Aprano
On 11/05/13 07:19, Jim Mooney wrote: If I'm using a variable-dependent range in a for loop, is Python smart enough to figure the variable once so I don't have to hoist it up? That is for c in range(0,x+2), is x+2 figured once or every time through the loop? I'm assuming it's once but I like to v

Re: [Tutor] range efficiency

2013-05-10 Thread Prasad, Ramit
Jim Mooney wrote: > If I'm using a variable-dependent range in a for loop, is Python smart > enough to figure the variable once so I don't have to hoist it up? > > That is for c in range(0,x+2), is x+2 figured once or every time > through the loop? I'm assuming it's once but I like to verify. > >

Re: [Tutor] range efficiency

2013-05-10 Thread Dave Angel
On 05/10/2013 05:19 PM, Jim Mooney wrote: If I'm using a variable-dependent range in a for loop, is Python smart enough to figure the variable once so I don't have to hoist it up? That is for c in range(0,x+2), is x+2 figured once or every time through the loop? I'm assuming it's once but I like

[Tutor] range efficiency

2013-05-10 Thread Jim Mooney
If I'm using a variable-dependent range in a for loop, is Python smart enough to figure the variable once so I don't have to hoist it up? That is for c in range(0,x+2), is x+2 figured once or every time through the loop? I'm assuming it's once but I like to verify. I'll figure this myself once I