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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -