-6

I have more than 300 variables in a list and i have to make a list of each variables:

example:

x=['aze','qsd','frz']...

i want:

MAXaze=[]
MAXqsd=[]
MAXfrz=[]
...

without typing them

Thank you for the help

mathieu
  • 55
  • 1
  • 8

2 Answers2

1

You can use a dictionary to store the values:

x=['aze','qsd','frz',...]
vars = {}
for i in x:
    vars["MAX" + i] = []

Or in order for them to become real variables you can add them to globals:

x=['aze','qsd','frz',...]
for i in x:
    globals()["MAX" + i] = []

You can now use:

MAXaze = [1,2,3]
Nick is tired
  • 6,860
  • 20
  • 39
  • 51
0

The easiest way that comes to my mind is by using exec. But be aware that there are security issues related to exec.

x=['aze','qsd','frz']
for i in x:
    exec('{}=[]'.format(i))
alec_djinn
  • 10,104
  • 8
  • 46
  • 71