On Wed, 18 May 2005 12:56:50 +0100, "Luis P. Mendes" <[EMAIL PROTECTED]> wrote:
> The reason why I'm using six nested for loops is because I need to find > the best output using those six variables as input. > Here's the simplified code: > for per in range(): > ~ for s in range(): > ~ for t in range(): > for v in range(): > ~ for n in range(): > ~ for l in range(): > var a, \ > var b, \ > ... > var 15 = function1(arg1, \ > ... > arg20) > ~ var a, \ > var d, \ > var a, \ > ... > var 14 = function2(arg1, \ > ... > arg25) > var c, \ > ... > var 18 = function3(arg1, \ > ... > arg20) > ia = var1*var2-numPerdidos*sl > > result.insert(index, [per,s,t,v,n,l,ia]) > index = index + 1 > thanks for the replies I don't know how large your search-space is, but if the ranges for s, t, v, n, and/or l don't change, at the very least you can pre-compute those ranges instead of creating a new list with range every time: srange = range( <whatever> ) trange = range( <whatever> ) vrange = range( <whatever> ) nrange = range( <whatever> ) lrange = range( <whatever> ) for per in range( <whatever> ): for s in srange: for t in trange: for v = vrange: for n in nrange: for l in nrange: somevar = somefunction( per, s, t, v, n, l ) result.append( [ somevar, per, s, t, v, n, l ] ) (Appending the results is probably quicker than inserting them, but I don't know for sure.) But a better-than-an-exhaustive-search algorithm sounds like a good idea, too. Regards, Dan -- Dan Sommers <http://www.tombstonezero.net/dan/> -- http://mail.python.org/mailman/listinfo/python-list