I have a python list as follows:
data = [1,2,3,4,5]
I want to write it in text file as follows:
1,2,3,4,5 ##as comma delineated.
I tried as:
with open ('data.txt', 'w') as fo:
for d in data:
fo.write(str(d) + '\n')
But it wrote data as follows:
1
2
3
4
5
How would you do it guys?
EDIT:
I will also have other lists obtained from for-loop, so all the one list i.e., 1,2,3,4,5 have to be adjusted in one line. In addition, I need faster performance.