-4
import csv
data = ["Apparels,Clothings,Materials,Bazaar,Saree,Salwars"]
f = open('data.csv', 'w')
w = csv.writer(f, delimiter = ',')
w.writerows([x.split(',') for x in data])
f.close()

I used the following code to write a list into a csv file. The problem I'm having is that, the new csv file (EXCEL.Doc) is spaced out as in the attachments. I would like the new file to be like the old one not spaced out.enter image description hereenter image description here

1 Answers1

0

By the help of juanpa.arrivillaga, the answer he gave worked magic!!

import csv
data = ["Apparels,Clothings,Materials,Bazaar,Saree,Salwars"]
f = open('data.csv', 'w', newline='') # by adding newline=''
w = csv.writer(f, delimiter = ',')
w.writerows([x.split(',') for x in data])
f.close()