Re: "for" cycle with assigning index

2009-08-15 Thread dmitrey
Thanks all, especially Dennis for your detailed answer. left_arr_indexes is list of nonnegative integers, eg [0,0,0,1,1,4] IndDict is a dict like {0: [1,2], 3: [0,1], 10:[0,2,3]}, so that's why I don't use python list instead. The code is taken from OpenOpt framework that I develop. Currently I hav

Re: "for" cycle with assigning index

2009-08-15 Thread Paul Rubin
Carl Banks writes: > def create_funcs_caller(i): > def func(*args,**kwargs): > return(Funcs2[i](*args,**kwargs)[IndDict[left_arr_indexes[i]]]) > retirm func > > for i in xrange(len(Funcs2)): > Funcs.append(create_funcs_caller(i)) I prefer to get rid of the index variable:

Re: "for" cycle with assigning index

2009-08-15 Thread Carl Banks
On Aug 15, 12:17 am, dmitrey wrote: > Hi all, > could you inform me how to do it properly? > > I have the cycle > > for i in xrange(len(Funcs2)): # Funcs2 is Python dict >      Funcs.append(lambda *args, **kwargs: (Funcs2[i](*args, **kwargs) > [IndDict[left_arr_indexes[i]]])) > > So, all the Funcs

"for" cycle with assigning index

2009-08-15 Thread dmitrey
Hi all, could you inform me how to do it properly? I have the cycle for i in xrange(len(Funcs2)): # Funcs2 is Python dict Funcs.append(lambda *args, **kwargs: (Funcs2[i](*args, **kwargs) [IndDict[left_arr_indexes[i]]])) So, all the Funcs are initialized with i = last index = len(Funcs2) Wh