|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
有大佬能帮我精简一下代码吗?可能是因为处理量太大和嵌套的原因,这一部分在jupyter notebook 上没法运行一直是【*】的状态
f=open('my_senti_dict','r')
line=f.readline()
#[['2736', ['A', 'paper', 'mill', 'in', 'the', 'central', 'Maine', 'town', 'of', 'Madison', 'soon', 'will', 'have', 'a', 'new', 'owner'], 0, 0, 0]]
for [a,b,c,d,e] in new_list:
t=[a,b,c,d,e]
for word in b:
if word not in txt:
continue
while word not in line:
line=f.readline()
q=line.find(',')
p=line.find(',',q+1)
num=line[p+1:].split(',')
c+=int(num[0])
d+=int(num[1])
e+=int(num[2][0])
if max(c,d,e)==c:
t.append('positive')
if max(c,d,e)==d:
t.append('neutral')
if max(c,d,e)==e:
t.append('negative')
print(t)
|
|