#User's appropriate Input
header_list = ['Hogehoge', 'Fuga Fuga', 'Hogefuga']
vars = [25.7,13.2,12.5]
coef_list = []
for no,(header,var) in enumerate(zip(header_list,vars)):
coef_list.append(dict(name = 'coef'+str(no),header=header,var=var))
# output
#Sample coefficient dictionary(dict type)
print(coef_list)
>> [{'name': 'coef0', 'header': 'Hogehoge', 'var': 25.7},
{'name': 'coef1', 'header': 'Fuga Fuga', 'var': 13.2},
{'name': 'coef2', 'header': 'Hogefuga', 'var': 12.5}]
#Extract name and var from dict type and define them as variables.
for coef in coef_list:
exec('{name} = {var}'.format(name = coef['name'], var = coef['var']))
print(coef0)
print(coef1)
print(coef2)
# output
>> 25.7
>> 13.2
>> 12.5
Recommended Posts