data_garden data_garden - 10 days ago 5
Python Question

Max value and item in a list of tuples?

In this list of tuples, I wish to fetch

max
float value and its correspondent string:

tuples = [(0, u'nope1'), (0.006535947712418301, u'target'), (0, u'nope2'),
(0, u'nope3')]


If I:

map(max,zip(*tuples))


it prints:

[0.006535947712418301, u'nope3']


but I need:

[0.006535947712418301, u'target']


How?

Answer
tuples = [(0, u'nope1'), (0.006535947712418301, u'target'), (0, u'nope2'), (0, u'nope3')]

print(max(tuples))

will give the answer