python - Turning a list of strings into the names of tables -


i'm trying generate tables within "for" loop. i'm stuck on need allow string in tablenames name of table.

tablenames = ['t_10', 't_20', 't_30', 't_40', 't_50', 't_60', 't_70', 't_80', 't_90', 't_100'] firstrow = ['10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%', '100%']  t, r, in zip(tablenames, firstrow):     t = [[r, '']]     

here's ended doing - know, it's not pretty (i know there's way generate number of spaces wanted...it not cooperating...also, cond1 , cond0 lists odd....)

t_10 = [['10%', '', '', '', '', '', '', '', '', '','','','']] t_20 = [['20%', '', '', '', '', '', '', '', '', '','','','']] t_30 = [['30%', '', '', '', '', '', '', '', '', '','','','']] t_40 = [['40%', '', '', '', '', '', '', '', '', '','','','']] t_50 = [['50%', '', '', '', '', '', '', '', '', '','','','']] t_60 = [['60%', '', '', '', '', '', '', '', '', '','','','']] t_70 = [['70%', '', '', '', '', '', '', '', '', '','','','']] t_80 = [['80%', '', '', '', '', '', '', '', '', '','','','']] t_90 = [['90%', '', '', '', '', '', '', '', '', '','','','']] t_100 = [['100%', '', '', '', '', '', '', '', '', '','','','']]   tnames = [t_10, t_20, t_30, t_40, t_50, t_60, t_70, t_80, t_90, t_100]  cond1 = [conditions_list[0], conditions_list[2], conditions_list[4], conditions_list[6], conditions_list[8]] cond0 = [conditions_list[1], conditions_list[3], conditions_list[5], conditions_list[7], conditions_list[9]]  t, c1, c0 in zip(tnames,cond1,cond0):     c1_results = process_exhaust(c1,1)     c0_results = process_exhaust(c0, 0)         t.append(c1_results[0])     t.append(c1_results[1])     t.append(c1_results[2])     t.append(c0_results[0])     t.append(c1_results[3])     t.append(c0_results[1]) 

trying programmatically create variable names bad idea. can exec, better approach use dictionary.

d = {t: [r,] t, r in zip(tablenames, firstrow)} 

now can d["t_10"] output desire.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -