Я написал ниже образец текста.Я хочу добавить этот текст в структуру данных списка в python.Сначала я разделил этот текст, используя '<EOS>'
в качестве разделителя.А затем добавьте каждый элемент результата метода split в тип данных list.
Но я сталкиваюсь с тем, что метод split
разделяет текст с '\n'
и '<EOS>'
в качестве разделителей.,Из-за этого теперь к типу данных списка добавляется одна строка, но не полная часть.
Пожалуйста, посмотрите на код, следующий за приведенным ниже примером текста, и дайте мне знать, что я делаю неправильно.
Old Major, the old boar on the Manor Farm, summons the animals on the farm together for a meeting, during which he refers to humans as "enemies" and teaches the animals a revolutionary song called "Beasts of England".
When Major dies, two young pigs, Snowball and Napoleon, assume command and consider it a duty to prepare for the Rebellion.<EOS>
Alex is a 15-year-old living in near-future dystopian England who leads his gang on a night of opportunistic, random "ultra-violence".
Alex's friends ("droogs" in the novel's Anglo-Russian slang, 'Nadsat') are Dim, a slow-witted bruiser who is the gang's muscle; Georgie, an ambitious second-in-command; and Pete, who mostly plays along as the droogs indulge their taste for ultra-violence.
Characterised as a sociopath and a hardened juvenile delinquent, Alex also displays intelligence, quick wit, and a predilection for classical music; he is particularly fond of Beethoven, referred to as "Lovely Ludwig Van".`
Код Python для чтения документов в виде списка:
f=open('./plots')
documents=[]
for x in f:
documents.append(x.split('<EOS>'))
print documents[0]
#documents[0] must start from 'Old Major' and stops at 'Rebellion'.