So, I am making a program that takes a text file, breaks it into words, and then writes the list to a new text file.
The problem I am facing is that I need the lines in the list with double quotes, not single quotes.
for instance
I get it ['dog','cat','fish']when I need this["dog","cat","fish"]
Here is my code
with open('input.txt') as f:
file = f.readlines()
nonewline = []
for x in file:
nonewline.append(x[:-1])
words = []
for x in nonewline:
words = words + x.split()
textfile = open('output.txt','w')
textfile.write(str(words))
I am new to python and haven't found anything about this. Does anyone know how to solve this?
[Edit: I forgot to mention that I used the output in the arduino project, which required the list to have double quotes.]
source
share