0
    d = {}
    for i in range(len(Active_Member)):
        d["Member_{0}".format(i)] = Active_Member[i]
    print(d)
    for i in range(len(d)):
        (Member_[d]) = (Member_[i](4))

Active_Member is already defined and the dictionary has been filled with around 13 values.

I am trying to make each value in the dictionary get put into its own variable but the amount of values that will be in the dictionary can be subject to change and therefore I cannot hard code this.

I am quite new to Python and probably a bit over me head however any help would be appreciated.

Hagrid
  • 3
  • 1
  • 4
    Why do you need variables when you already have everything in a dict? – ekhumoro Feb 28 '20 at 15:32
  • 1
    Also why are you using a dict? just use a list and access by index since your member names are `Member_0`, `Member_1`... – Jab Feb 28 '20 at 15:37
  • Does this answer your question? [How do I create a variable number of variables?](https://stackoverflow.com/questions/1373164/how-do-i-create-a-variable-number-of-variables) – Tomerikoo Feb 28 '20 at 15:39

2 Answers2

-2

say we have a dictionary like

dictionary = {'a':1, 'b':2, 'c':3, 'd':4}

we can iterate over all of the dictionary keys and make them variables with there respective values by doing

for key,val in dictionary.items():
    exec(key + '=val')

Hope that helps!

Max Miller
  • 45
  • 5
-3

take a look at the accepted answer of this question: Programmatically creating variables in Python

However I strongly recommend to overthink why you want separate variables

Raphael
  • 1,677
  • 2
  • 6
  • 21
  • If you believe there is already an answer to this question somewhere else, mark it as duplicate. Don't quote or link the answer as a new answer... – Tomerikoo Feb 28 '20 at 15:38