Lets say I have some variables that can take pre-setted values:
var1 = [1,2,3]
var2 = [10,20,30]
I could hardcode a loop over all like this:
for var1 in [1,2,3]:
for var2 in [10,20,30]:
do something with var1 and var2
How could I do this if I want to pre-specify variables and values though? If I have a dictionary storing the variables and values I want to loop through:
variables2loop = {'var1' : [1,2,3],
'var2' : [10,20,30]}
I tried:
for var in variables2loop.keys():
for value in variables2loop[var]:
locals()[var] = value
do something with var1 and var2
But this is not doing all combinations, and also it is not working properly. It goes through all values per variable BEFORE the do something command.
How can a for loop like this be implemented, if I want to dynamically change the variables and values that will be used in the script?