I'm checking some averages for different categories
cat_1 = []
for i, j, k in zip(is, js, ks):
if i == 1:
cat_1.append(i)
avg_cat_1 = stats.mean(cat_1)
print("Avg for cat_1:", avg_cat_1)
If I want to include multiple categories I would like to avoid having to write a new line for each new category.
For the initialization of the lists I could do something like this:
for i in range(nr of categories):
a = "cat_%s" % (i)
print (a)
but that of course only prints me a line and doesnt execute one and for the if statements thats even more complicated.
I wonder if there is a way to just do a loop like this:
for i in range(nr of categories):
cat_i = []
or
for i in range(nr of categories):
cat_%s = [] %(i)
where the "i" gets recognized not as part of the variable string but as the temporary loop variable and just produces a executable line of code and not just a print out