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... > > > > > > for i in range(100): > > > for j in range(100): > > > do_something((i + N) % 100, (j + M) % 100) > > > > Both of these approaches move the modifications to the sequence into the > > body of the loop. It may be preferable to iterate over the desired > > sequence directly. E.g. > > > > for i in ((N + ii) % 100 for ii in xrange(100)): > > for j in ((M + jj) % 100 for jj in xrange(100)): > > do_something(i, j)
list(range(N,100))+ list(range(0,N)) //good for j Well, this is the way! -- http://mail.python.org/mailman/listinfo/python-list