我用WordBlob从文本文档创建了一个列表。现在我想创建一个在每个列表中差异最大的列表,我只对极性感兴趣。我想把最高和最低的数字加在另一个列表上,然后把它们相互减去。但我怎么能引用“极性”中的数字呢?这是我的嵌套列表:
[[Sentiment(polarity=0.35, subjectivity=0.65),
Sentiment(polarity=0.0, subjectivity=0.0),
Sentiment(polarity=0.0, subjectivity=0.0),
Sentiment(polarity=0.6, subjectivity=0.87),
Sentiment(polarity=0.0, subjectivity=0.0),
Sentiment(polarity=0.0, subjectivity=0.0)],
[Sentiment(polarity=0.0, subjectivity=0.0),
Sentiment(polarity=0.5, subjectivity=0.8),
Sentiment(polarity=0.0, subjectivity=0.0),
Sentiment(polarity=-0.29, subjectivity=0.54),
Sentiment(polarity=0.0, subjectivity=0.0),
Sentiment(polarity=0.25, subjectivity=1.0)],
[Sentiment(polarity=0.5, subjectivity=0.8),
Sentiment(polarity=0.0, subjectivity=0.0)]]
有人有主意吗?谢谢你的帮助。你知道吗
您可以使用python内置函数
min
和max
以及它们的key
参数,在给定键条件的情况下,查找列表中的最小/最大值。作为函数编写,它可以如下所示:给定一个虚拟物体和一些测试数据-
-结果如下:
给出了一个示例类,该类描述了如何访问案例中所需的元素:
相关问题 更多 >
编程相关推荐