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

jQuery clickable div with working mailto link inside -

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -