Post

PythonPython

r
rushi chowdary

Posted on 27th February 2024|16 views

0
votes

Write List To Csv Python

How to save a list as a .CSV file with python with new lines?

I want to save a list in a .CSV file assume i have a list like this

[‘welcome’, ‘to’, ‘mindmajix’]

But I want to save it like this

welcome

to

mindmajix 

I tried this

afile = open('/Users/user/Projects/list.csv', 'wb') 

wr = csv.writer(afile, quoting=csv.QUOTE_ALL,'\n') 

wr.writerow(pos_score)

 

Answers
P
chris bons

Posted on 27th February 2024

If you are willing to print the words in the different lines then just set the delimiter to \n just like this

s = ['welcome','to','mindmajix'] 

import csv with open("out.csv","w") as f: 

wr = csv.writer(f,delimiter="\n") 

wr.writerow(s)

Output:

welcome 

to 

mindmajix 

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos