I am trying to create dynamic variable names as part of a loop and assign then appropriate values. To demonstrate more clearly what I am after I have created this demonstration code:
var1 = ["one","two","three"]
var2 = ["red","blue","green"]
for i in 0 to 2:
var3 = var1[i] #cycle through first list
var4 = var2[i] #cycle through second list
var5 = var3,var4 #make the name of var5 a concatenation of var 3 and var 4
var5 = 1 #assign this dynamic variable name an arbitary value
print var5
The bit that I am just not sure how to approach is the line var5 = var3,var4. I'm not even sure that this is the best way to approach the problem. Could someone please:
1) Fill in the blank the line referenced above 2) Suggest an alternative syntax altogether
The reason I need dynamic variable names is in my real code I am using for loops where each number in the loop has different conditions attached to it. Apologies if I am a little off beam with my methodology.
EDIT:
The responses I have had suggest I have not articulated what I require clearly. My sample output needs to be of the format:
one_red = 1
two_blue = 1
three_green = 1
The reason why I require these to have different variable names is that I will eventually be joining my outputs together. So my final output would be:
111
The joining section is unimportant for now, but what is important is that I am programatically creating variables in a loop that will each be assigned their own value.
Thanks