I want to transform a folder of text documents in the following format:
texts = ['text of document 1', 'text of document 2', 'text of document 3',...]
in order to apply text mining methods.
So far my code is the following:
import os
file= "*.txt"
path = "C:\\"
texts=[]
for files in os.listdir(path):
with open(path + files) as f:
for x in f:
texts.append(x)
Unfortunately, the outcome differs from the wanted one:
texts = ['line 1 of document 1', 'line 2 of document 1', …]
What am I doing wrongly? Can anybody suggest an improvement for my code?