硬干的话大概长这样
虽然说我收到这样的csv 我会很生气
column_name = ["a", "b", "c"]
column_key = "_key"
column_value = "_value"
a_dic = {"a": "xxx", "b": "yyy"}
b_dic = {"c": "zzz", "d": "vvv", "e": "ttt"}
c_dic = {"f": "uuu"}
dics = [a_dic, b_dic, c_dic]
max_len = max([len(i) for i in dics])
res = ""
first_line = ''.join([f"{i + column_key:10}" + f"{i + column_value:10}" for i
in column_name])
res += first_line + "\n"
for i in range(max_len):
res_line = ''
for dic in dics:
dic_tuple = tuple(dic.items())
if i >= len(dic):
rr = f"{'':20}"
else:
rr = f"{dic_tuple[i][0]:10}" + f"{dic_tuple[i][1]:10}"
res_line += rr
res += (res_line + '\n')
print(res)