1

Say I want to create a new list every (in a loop) time the variable i (an integer) changes, eg:

game_1 = []

game_2 = []

game_3 = []

...

game_i = []

How would I do this?

I've tried putting game_i, which obviously doesn't work; neither does game[i],

Kevin Fang
  • 1,966
  • 2
  • 16
  • 31
Long Vuong
  • 181
  • 1
  • 1
  • 9

2 Answers2

3

I guess you are trying to dynamically name variables. This issue has been discussed before, check This link for details of alternatives.

Edit: second link you should consider Link

Wazaki
  • 899
  • 1
  • 8
  • 22
2
gb = globals()
for i in range(10):
    gb['game_{0}'.format(i)] = []
Pratik Patel
  • 353
  • 2
  • 6