Re: looking for a neat solution to a nested loop problem

2012-08-14 Thread 88888 Dihedral
Nobody於 2012年8月7日星期二UTC+8下午11時32分55秒寫道: > On Mon, 06 Aug 2012 21:02:33 -0700, Larry Hudson wrote: > > > > >> for i in range(N,N+100): > > >> for j in range(M,M+100): > > >> do_something(i % 100 ,j % 100) > > >> > > >> Emile > > > > > > How about... > > > >

Re: looking for a neat solution to a nested loop problem

2012-08-09 Thread 88888 Dihedral
Nobody於 2012年8月7日星期二UTC+8下午11時32分55秒寫道: > On Mon, 06 Aug 2012 21:02:33 -0700, Larry Hudson wrote: > > > > >> for i in range(N,N+100): > > >> for j in range(M,M+100): > > >> do_something(i % 100 ,j % 100) > > >> > > >> Emile > > > > > > How about... > > > >

Re: looking for a neat solution to a nested loop problem

2012-08-09 Thread 88888 Dihedral
Nobody於 2012年8月7日星期二UTC+8下午11時32分55秒寫道: > On Mon, 06 Aug 2012 21:02:33 -0700, Larry Hudson wrote: > > > > >> for i in range(N,N+100): > > >> for j in range(M,M+100): > > >> do_something(i % 100 ,j % 100) > > >> > > >> Emile > > > > > > How about... > > > >

Re: looking for a neat solution to a nested loop problem

2012-08-07 Thread 88888 Dihedral
Nobody於 2012年8月7日星期二UTC+8下午11時32分55秒寫道: > On Mon, 06 Aug 2012 21:02:33 -0700, Larry Hudson wrote: > > > > >> for i in range(N,N+100): > > >> for j in range(M,M+100): > > >> do_something(i % 100 ,j % 100) > > >> > > >> Emile > > > > > > How about... > > > >

Re: looking for a neat solution to a nested loop problem

2012-08-07 Thread Nobody
On Mon, 06 Aug 2012 21:02:33 -0700, Larry Hudson wrote: >> for i in range(N,N+100): >> for j in range(M,M+100): >> do_something(i % 100 ,j % 100) >> >> Emile > > How about... > > for i in range(100): > for j in range(100): > do_something((i + N) % 100,

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Larry Hudson
On 08/06/2012 11:11 AM, Emile van Sebille wrote: for i in range(N,N+100): for j in range(M,M+100): do_something(i % 100 ,j % 100) Emile How about... for i in range(100): for j in range(100): do_something((i + N) % 100, (j + M) % 100) -=- La

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Steven D'Aprano
On Mon, 06 Aug 2012 19:16:45 +0200, Tom P wrote: >> def my_generator(): >> yield 9 >> yield 100 >> for i in range(200, 250): >> yield i >> yield 5 >> >> > Thanks, I'll look at that but I think it just moves the clunkiness from > one place in the code to another. And i

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Arnaud Delobelle
On 6 August 2012 16:52, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but some > other values i = N and j = M, and I want to iterate through a

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Emile van Sebille
On 8/6/2012 12:22 PM Grant Edwards said... On 2012-08-06, Tom P wrote: ah, that looks good - I guess it works in 2.x as well? I don't know. Let me test that for you... Yes, it works in 2.x as well. :) And from the docs, all the way back to 2.3! 9.7. itertools Functions creati

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Grant Edwards
On 2012-08-06, Tom P wrote: no, I meant something else .. j runs through range(M, 100) and then range(0,M), and i runs through range(N,100) and then range(0,N) >>> >>> In 2.x: >>> >>> for i in range(M,100)+range(0,M): >>> for j in range(N,100)+range(0,N): >>>

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Tom P
On 08/06/2012 08:29 PM, Grant Edwards wrote: On 2012-08-06, Grant Edwards wrote: On 2012-08-06, Tom P wrote: On 08/06/2012 06:18 PM, Nobody wrote: On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: consider a nested loop algorithm - for i in range(100): for j in range(100):

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Grant Edwards
On 2012-08-06, Tom P wrote: > On 08/06/2012 06:18 PM, Nobody wrote: >> On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: >> >>> consider a nested loop algorithm - >>> >>> for i in range(100): >>> for j in range(100): >>> do_something(i,j) >>> >>> Now, suppose I don't want to use i =

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Grant Edwards
On 2012-08-06, Grant Edwards wrote: > On 2012-08-06, Tom P wrote: >> On 08/06/2012 06:18 PM, Nobody wrote: >>> On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: >>> consider a nested loop algorithm - for i in range(100): for j in range(100): do_something(i,

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread André Malo
* Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but > some other values i = N and j = M, and I want to iterate through all > 10,000 value

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Emile van Sebille
On 8/6/2012 10:14 AM Tom P said... On 08/06/2012 06:18 PM, Nobody wrote: On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: consider a nested loop algorithm - for i in range(100): for j in range(100): do_something(i,j) Now, suppose I don't want to use i = 0 and j = 0 as initial

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Oscar Benjamin
On 6 August 2012 18:14, Tom P wrote: > On 08/06/2012 06:18 PM, Nobody wrote: > >> On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: >> >> consider a nested loop algorithm - >>> >>> for i in range(100): >>> for j in range(100): >>> do_something(i,j) >>> >>> Now, suppose I don't wan

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Tom P
On 08/06/2012 06:03 PM, John Gordon wrote: In Tom P writes: consider a nested loop algorithm - for i in range(100): for j in range(100): do_something(i,j) Now, suppose I don't want to use i = 0 and j = 0 as initial values, but some other values i = N and j = M, and I wan

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Tom P
On 08/06/2012 06:18 PM, Nobody wrote: On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: consider a nested loop algorithm - for i in range(100): for j in range(100): do_something(i,j) Now, suppose I don't want to use i = 0 and j = 0 as initial values, but some other values i = N

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Nobody
On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but > some other values i = N and j = M, and I want to

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Ian Foote
The function range can be called with more than one argument. For example: for i in range(N, N + 10): for j in range(M, M + 100): do_something(i, j) You can also call range with 3 arguments, if want a step size different to 1: for k in range(2, 11, 3): print(k) 2 5 8 Hope th

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread John Gordon
In Tom P writes: > consider a nested loop algorithm - > for i in range(100): > for j in range(100): > do_something(i,j) > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but > some other values i = N and j = M, and I want to iterate through all > 10,000 valu

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Ethan Furman
Tom P wrote: consider a nested loop algorithm - for i in range(100): for j in range(100): do_something(i,j) Now, suppose I don't want to use i = 0 and j = 0 as initial values, but some other values i = N and j = M, and I want to iterate through all 10,000 values in sequence - is t

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Oscar Benjamin
On 6 August 2012 16:52, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but > some other values i = N and j = M, and I want to iterate through

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Oscar Benjamin
Are you familiar with the itertools module? itertools.product is designed for this purpose: http://docs.python.org/library/itertools#itertools.product Oscar. On 6 August 2012 16:52, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): >