Python 元组列表中的最大值和项?
在这个元组列表中,我希望获取Python 元组列表中的最大值和项?,python,list,tuples,Python,List,Tuples,在这个元组列表中,我希望获取maxfloat值及其对应的字符串: tuples = [(0, u'nope1'), (0.006535947712418301, u'target'), (0, u'nope2'), (0, u'nope3')] 如果我: 它打印: [0.006535947712418301, u'nope3'] 但我需要: [0.006535947712418301, u'target'] 怎么做 将给出答案我只是简单地尝试一下 max(tuples)
max
float值及其对应的字符串:
tuples = [(0, u'nope1'), (0.006535947712418301, u'target'), (0, u'nope2'),
(0, u'nope3')]
如果我:
它打印:
[0.006535947712418301, u'nope3']
但我需要:
[0.006535947712418301, u'target']
怎么做
将给出答案我只是简单地尝试一下
max(tuples)
它可以工作。列表(最大(元组))
?
tuples = [(0, u'nope1'), (0.006535947712418301, u'target'), (0, u'nope2'), (0, u'nope3')]
print(max(tuples))
max(tuples)