python - How to call variables generated in loop -
i need generate number of variables in loop. achieved using code:
nbottom=list of unknown size loc=locals() k,val in enumerate(nbottom) : loc["imp_local"+str(k)]=700 k,val in enumerate(nbottom) : loc["imp_global"+str(k)]=600
now need work them, creating dictionary like:
dic1={'imp_local0': 700, ..., 'imp_localn': 700} dic2={'imp_global0': 700, ..., 'imp_globaln': 700}
how can this?
don't generate local variables. generate dictionary:
dict1 = {'imp_local'+str(k):700 k,val in enumerate(nbottom)} dict2 = {'imp_global'+str(k):600 k,val in enumerate(nbottom)}
refer dict comprehensions (pep 274) details
Comments
Post a Comment