python - How can you dynamically create variables via a while loop? -


this question has answer here:

i want create variables dynamically via while loop in python. have creative means of doing this?

unless there overwhelming need create mess of variable names, use dictionary, can dynamically create key names , associate value each.

a = {} k = 0 while k < 10:     <dynamically create key>      key = ...     <calculate value>      value = ...     a[key] = value      k += 1 

there interesting data structures in new 'collections' module might applicable:

http://docs.python.org/dev/library/collections.html


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -