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

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -