Ceem Ceem - 11 months ago 33
Python Question

How to read a set of text files in to a single list in python

I have a set of text files and i am trying to read it into a single list.but when i execute my code

def get_documents():
path1 = "D:/set/"
listing1 = os.listdir(path1)
for file in listing1:
with open(path1+file,'r') as f:
lines = f.read().splitlines()
print texts

I am getting output as list of lists

[['Wanna see Riya Somani :) wish lyf olso moment lyk end half galfrnd... :) '], ['Worst book Mr. Chetan Bhagat.. Plz better stori ']]

How can i get it as a single list?


I believe instead of this:


Do this: