How to save one list in a text file in Python

0 votes

Hi Guys,

I have one list. I want to save this list in a file. How can I do this?

Jun 25, 2020 in Python by akhtar
• 38,260 points
3,797 views

1 answer to this question.

0 votes

Hi@akhtar,

There is no inbuilt function available to save one list. But you can use a python script to save one list in a text file. I have attached one python script below.

list =['Hello','How are you?','Bye']
with open("list.txt", "w") as f:
    for s in list:
        f.write(str(s) +"\n")

I hope this will help you.

answered Jun 25, 2020 by MD
• 95,460 points

Related Questions In Python

0 votes
1 answer

How to list only text files in a directory using python?

Well, you are using a complex way. ...READ MORE

answered Feb 4, 2019 in Python by Omkar
• 69,220 points
2,770 views
0 votes
0 answers

How can we read a text file in a list in python?

Can you give the sample code as ...READ MORE

Jun 18, 2019 in Python by Waseem
• 4,540 points
560 views
0 votes
0 answers
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,466 views
0 votes
1 answer
0 votes
1 answer

How to transfer multiple lines in a file using python?

Hi@akhtar, I don't know it will help you ...READ MORE

answered Mar 31, 2020 in Python by MD
• 95,460 points
1,174 views
0 votes
1 answer

How to call a function from another file in Python?

Hi@akhtar, You can use the import keyword to ...READ MORE

answered Jun 24, 2020 in Python by MD
• 95,460 points
5,301 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP