I searched high and low but I didnt got a solution.
I have a list
a=['a','b','c']
for i in a:
"%s_variable_name"%i=i
So the as per my use case, I require 3 dynamically created variable names with values like,
a_variable_name=a
b_variable_name=b
c_variable_name=c
I have tried the possibilities but the above method dont work in python. Please help me out if there any ways to assign variable referenced with in variable names.
One work around I have is using a dict and keeping them in key value pairs
d={}
for i in a:
d["%s_variable_name"%i]=i
SO I get dict d with expected response as key value pairs but I just wanted to know if there any possibilities with the first method I told above.
Thanks in advance.
Response: Thanks Chris, Quadri and Zero for the comments. I know its a bad method of assigning variable names but just wanted to know the possibilities. I will stick with dict as Chris said but the method Zero mentioned is perfectly works.
list=['a','b','c']
for i in list:
globals()["%s_variable_name"%i] = i
In [43]: a_variable_name
Out[43]: 'a'
In [44]: b_variable_name
Out[44]: 'b'
In [45]: c_variable_name
Out[45]: 'c'
Thanks