0

For the game I'm working on, the players will have four options to choose to specialize in one of five categories. The category they choose will determine their rate of stat growth. I am trying to write a quick program that will let me analyze the variance of the different specialization choices to find a good range for my numbers. Using itertools I have been able to create a list of all the possible choices (625) then using enumerate with globals I have been able to assign each of those to their own numbered variable and using a similar process I have split the variables into the four separate components which has converted them all to tuples where var0[0] = Faith for example. I am now looking to convert the tuples into lists so that I can then iterate through all of the lists to say if list[0] == faith list[0] = 10 if list[1] == faith, list [1] = 15 for example and then have the program sum the lists. Where I am stuck is converting the tuples into lists. I have:

import itertools

Classes = ['Faith', 'Knowledge', 'Skill', 'Might', 'Magic']
Class_Combinations = []

for c in itertools.product(Classes,repeat = 4):
    Class_Combinations.append(c)
length = len(Class_Combinations)
print(length)

for n, val in enumerate(Class_Combinations):
    globals()["var%d"%n] = val
for vars in dir():
    if vars.startswith("var"):
        globals()["var%d"%n] = vars.split(",")

for vars in dir():
    if vars.startswith("var"):
        globals()["var%d"%n] = list(vars)

I have tried several versions of the final line but none of them create the list of lists that I'm looking for. Alternately if anyone knows how to take each of the tuples in the original Class_Combinations list and convert them into a series of lists of values to avoid the conversion to values and then splitting using vars.split. That would work as well.

Mythranor
  • 1
  • 4
  • 1
    I'm pretty sure all you need is `list(map(list, itertools.product(Classes, repeat=4))))`. There's absolutely no reason to be creating numbered variables for this, just create a list to start with. – Blckknght Feb 20 '16 at 08:10
  • 1
    Creating variables like that is generally a bad idea. There are better ways to handle your data, eg using a `dict`, a `class`, or a `namedtuple`. See [How do I do variable variables in Python?](http://stackoverflow.com/q/1373164/4014959) for some alternatives as well as explanations of why it's bad to create variables like your code does. – PM 2Ring Feb 20 '16 at 08:39

0 Answers0