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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -