python - How can you dynamically create variables via a while loop? -
this question has answer here:
- how create variable number of variables? 12 answers
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:
Comments
Post a Comment