I'm trying to make my code more 'Pythonic'.
At the moment I am calling a function 16 times, incrementing by 12 each time. I then add these variables to a dictionary and assign a key with the same name as the variable (value):
c1 = getIndividualCounts(42)
c2 = getIndividualCounts(54)
c3 = getIndividualCounts(66)
c4 = getIndividualCounts(78)
c5 = getIndividualCounts(90)
c6 = getIndividualCounts(102)
c7 = getIndividualCounts(114)
c8 = getIndividualCounts(126)
c9 = getIndividualCounts(138)
c10 = getIndividualCounts(150)
c11 = getIndividualCounts(162)
c12 = getIndividualCounts(174)
c13 = getIndividualCounts(186)
c14 = getIndividualCounts(198)
c15 = getIndividualCounts(210)
c16 = getIndividualCounts(222)
main_data = {'c1':c1, 'c2':c2, 'c3':c3, 'c4':c4, 'c5':c5, 'c6':c6, 'c7':c7, 'c8':c8, 'c9':c9, 'c10':c10, 'c11':c11, 'c12':c12, 'c013':c13, 'c14':c14, 'c15':c15, 'c16':c16}
This currently works fine, but is quite chunky. What I would like to do is the loop through the function 16 times, increasing the start index by 12 each time and auto-generating the dictionary and keys + values.
This is what I have so far:
index = 1
for i in range(16):
index += 12
getIndividualCounts(42) + index
return ({'c' + str(i) + ':'+ c + i} )
Needless to say it doesn't work. I've tried multiple iterations, but can't find any approach that works. As a relatively new Python programmer, I would also appreciate an explanation to a possible solution, so I can learn going forward.