1

I'm trying to write the ouput from list in the same line of a .txt file,so if my lists are a=[1,2,3] and b=[3,4,5]. I would like to have a .txt file like this: 1,2,3 3,4,5 Instead of this: 1 2 3 3 ... I would like to do somthing like:

for i in a:print i,

with the ",", but with output.write(i), it doesn't works. How can I do that? Thanks a lot!

1
  • Possible duplicate of this Commented Jun 29, 2013 at 7:51

2 Answers 2

1

Try putting it in a string before writing it

w=""
for i in a:
   w+=i+" "
output.write(w)

This writes everything in a single line

Sign up to request clarification or add additional context in comments.

Comments

0
output.write(','.join(map(str,i)))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.