I am new to python and need to write a loop which declares for every element in a list a function. These functions will then be used after the loop. The last element in the loop needs an extra treatment.
Suppose I have this list
elements = ['element_1' ,'element_2', 'element_3']
I tried:
for i, item in enumerate(elements) :
if (i+1) == len(elements):
def action(focus = 'action_' + str(i)) :
print ("action_" + str(i) + " : " + item)
.
.
.
else :
def action(focus = 'action_' + str(i)) :
print ("action_" + str(i) + " : " + item)
.
.
.