-1

I'd like to create a bunch of empty lists and name them thru iterations, but the code keeps error out showing "SyntaxError: can't assign to operator". My purpose is to create lists named 5R05D, 15R05D, 15R20D etc.. Appreciate for any help!

MA = ['5','15','30','60']
For each in MA:
    each+'R05D'=[]
    each+'R10D'=[]
    each+'R20D'=[]
pome
  • 79
  • 1
  • 3

1 Answers1

2

You can't create variables like that. For one thing, Python variable names can not start with a digit. You would be better off with a dictionary using '5R05D' (and similar) as a key, and lists as the values:

MA = ['5','15','30','60']
d = {}
for each in MA:
    d[each+'R05D'] = []
    d[each+'R10D'] = []
    d[each+'R20D'] = []

>>> d
{'5R05D': [], '5R10D': [], '5R20D': [], '15R05D': [], '15R10D': [], '15R20D': [], '30R05D': [], '30R10D': [], '30R20D': [], '60R05D': [], '60R10D': [], '60R20D': []}
mhawke
  • 84,695
  • 9
  • 117
  • 138