擅长:python、mysql、java
<p>假设最后一个“.”(点)后面的数字是<strong>标签</strong></p>
<p>对于给定的示例,当存储在文件中时你的数据.txt'下面的代码应该生成2个列表<code>sentence_list</code>和<code>label_list</code>。您可以将这些列表中的数据分别写入文件,然后根据您的要求。在</p>
<pre><code>fmov=open('yourdata.txt','r')
sentence_list=[]
label_list=[]
for f in fmov.readlines():
lineinfo=f.split('.')
sentenceline=".".join(lineinfo[0:-1])
sentence_list.append(sentenceline)
label_list.append(str(lineinfo[-1]).replace('\n',''))
print(sentence_list)
print(label_list)
OUT:
['A very, very, very slow-moving, aimless movie about a distressed, drifting young man', 'Not sure who was more lost - the flat characters or the audience, nearly half of whom walked out', 'Attempting artiness with black & white and clever camera angles, the movie disappointed - became even more ridiculous - as the acting was poor and the plot and lines almost non-existent', 'Very little music or anything to speak of']
[' 0', ' 0', ' 0', ' 0']
</code></pre>