data_garden data_garden - 3 days ago 5
Python Question

Python - max value and item in a list of tuples

In this list of tuples, I wish to fetch

max
float
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

Comments