而不是定義documents
這樣的......讀取文本文件到列表在Python
documents = ["the mayor of new york was there", "machine learning can be useful sometimes","new york mayor was present"]
...我想讀第一句兩個不同的txt文件相同的三句話中的第一個文件,第二個文件中的句子2和3。
我想出了這個代碼:
# read txt documents
os.chdir('text_data')
documents = []
for file in glob.glob("*.txt"): # read all txt files in working directory
file_content = open(file, "r")
lines = file_content.read().splitlines()
for line in lines:
documents.append(line)
但是從兩種策略產生的documents
似乎是在不同的格式。我想要第二個策略產生與第一個相同的輸出。
......怎麼了?請嘗試針對您的問題陳述進行具體說明。 –
爲了清晰起見進行了編輯。 – textnet
我的觀點是,代替寫「由兩種策略產生的'文檔'似乎是以不同的格式」,你應該改爲*顯示輸出* –