我有一组文本文件,我试图将其读入单个列表.但是当我执行我的代码时
def get_documents():
path1 = "D:/set/"
texts=[]
listing1 = os.listdir(path1)
for file in listing1:
with open(path1+file,'r') as f:
lines = f.read().splitlines()
texts.append(lines)
print texts
Run Code Online (Sandbox Code Playgroud)
我将输出作为列表列表
[['Wanna see Riya Somani :) wish lyf olso moment lyk end half galfrnd... :) '], ['Worst book Mr. Chetan Bhagat.. Plz better stori ']]
Run Code Online (Sandbox Code Playgroud)
我怎样才能将它作为一个列表?
我相信而不是这个:
texts.append(lines)
Run Code Online (Sandbox Code Playgroud)
做这个:
texts.extend(lines)
Run Code Online (Sandbox Code Playgroud)