You can also use slicing and a collections.defaultdict to collect your values:
from collections import defaultdict
column_names = ["a", "b", "c"]
values = [1, 2, 3, 4, 5, 6, 7, 8, 9]
column_len = len(column_names)
d = defaultdict(list)
for i in range(0, len(values), column_len):
seq = values[i:i+column_len]
for idx, number in enumerate(seq):
d[column_names[idx]].append(number)
for k, v in d.items():
print('%s = %s' % (k, ', '.join(map(str, v))))
Which Outputs:
a = 1, 4, 7
b = 2, 5, 8
c = 3, 6, 9
This can be imporoved if you create zipped lists with itertools.cycle, avoiding the slicing all together:
from collections import defaultdict
from itertools import cycle
column_names = ["a", "b", "c"]
values = [1, 2, 3, 4, 5, 6, 7, 8, 9]
column_names = cycle(column_names)
d = defaultdict(list)
for column, val in zip(column_names, values):
d[column].append(val)
for k, v in d.items():
print('%s = %s' % (k, ', '.join(map(str, v))))