Categories
Development Python

How can I convert a dictionary into a comma separated .txt file while maintaining the key:value pair? Python

I have a dictionary that I need to write in a .txt file in comma separated value format. I have tried mydict = {‘first’: [‘1′,’2′,’3’], ‘second’: [‘2′,’3′,’4’], ‘third’: [‘3′,’4′,’5’]} f = open(“doc.txt”,”w”) for key, values in mydict: f.write(‘,’.format(key, values)+”\n”) f.close() But it does not work , as the values are too many. I have also […]