我想将一个文档分为两个列表,但这段代码在两个列表中提供相同的数据。我定义了两个单独的字典,我也在这里使用
def feature_extractor(document):
support_features = []
attack_features = []
for sentence in document:
if (word in sentence for word in supporting_ethos):
support_features.append(sentence)
if (word in sentence for word in attacking_ethos):
attack_features.append(sentence)
return(attack_features , support_features)
(.. for .. in ...)
是generator expression当它被用作谓词时,它总是被当作真理
所以表达式
(word in sentence for word in supporting_ethos)
和(word in sentence for word in attacking_ethos)
都被计算为真值你的意思是将^{} 与生成器表达式一起使用吗
相关问题 更多 >
编程相关推荐