Python 2.7:将字典写入CSV文件

#!/bin/python

import csv

my_dict = {'Sno': ['22', '23', '34'], 'Name': ['Dinesh', 'Suresh', 'Mahesh']}


print(my_dict)

with open('Names.csv', 'w') as f:
    fieldnames = ['Age', 'Name']
    writer = csv.DictWriter(f, fieldnames=fieldnames)
    writer.writeheader()
    data = [dict(zip(fieldnames, [k, v])) for k, v in my_dict.items()]
    writer.writerows(data)

仅使用Python 2.7

我想像这样将其写入CSV文件:

Output: *Ouput*