还有其他关于该主题的问题,但我有不同的问题。
我有一个元组列表,可以通过从两个列表中找到最多三个分数和相应的值来制成:

score = [0.133961, 0.026456, 0.210888, 0.521684, 0.156776]
tone = [u'Anger', u'Disgust', u'Fear', u'Joy', u'Sadness']


并使用

highest_three = sorted(zip(score, tone_name), reverse = True)[:3]


得到输出:

[(0.521684,u'Joy'),(0.210888,u'Fear'),(0.156776,u'Sadness')]

现在我只想在输出中打印。

Joy, Fear, Sadness


我用了 :

emo = ', '.join ('{}'.format(*el) for el in highest_three)


但这会返回分数,我只想打印tone_name。有什么建议么 ?

最佳答案

用更少的代码修改:

score = [0.133961, 0.026456, 0.210888, 0.521684, 0.156776]
tone = [u'Anger', u'Disgust', u'Fear', u'Joy', u'Sadness']
highest_three = sorted(zip(score, tone), reverse = True)[:3]
print(','.join(v for _, v in highest_three))


输出:

Joy,Fear,Sadness

关于python - Python:从元组列表中提取值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42524182/

10-12 21:08